add zip unzip extract archive
This commit is contained in:
parent
0b250f2c4b
commit
e49187a1fa
20
go.mod
20
go.mod
@ -1,14 +1,14 @@
|
||||
module apigo.cc/gojs/util
|
||||
|
||||
go 1.24.0
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
apigo.cc/gojs v0.0.32
|
||||
apigo.cc/gojs v0.0.34
|
||||
apigo.cc/gojs/console v0.0.4
|
||||
github.com/ZZMarquis/gm v1.3.2
|
||||
github.com/emmansun/gmsm v0.40.0
|
||||
github.com/emmansun/gmsm v0.41.1
|
||||
github.com/obscuren/ecies v0.0.0-20150213224233-7c0f4a9b18d9
|
||||
github.com/ssgo/u v1.7.23
|
||||
github.com/ssgo/u v1.7.24
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
@ -16,12 +16,12 @@ require (
|
||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
||||
github.com/google/pprof v0.0.0-20250903194437-c28834ac2320 // indirect
|
||||
github.com/google/pprof v0.0.0-20260302011040-a15ffb7f9dcc // indirect
|
||||
github.com/ssgo/config v1.7.10 // indirect
|
||||
github.com/ssgo/log v1.7.10 // indirect
|
||||
github.com/ssgo/standard v1.7.7 // indirect
|
||||
github.com/ssgo/log v1.7.11 // indirect
|
||||
github.com/ssgo/standard v1.7.8 // indirect
|
||||
github.com/ssgo/tool v0.4.29 // indirect
|
||||
golang.org/x/crypto v0.46.0 // indirect
|
||||
golang.org/x/sys v0.39.0 // indirect
|
||||
golang.org/x/text v0.32.0 // indirect
|
||||
golang.org/x/crypto v0.48.0 // indirect
|
||||
golang.org/x/sys v0.42.0 // indirect
|
||||
golang.org/x/text v0.35.0 // indirect
|
||||
)
|
||||
|
||||
44
util.go
44
util.go
@ -701,6 +701,50 @@ func init() {
|
||||
return nil
|
||||
}
|
||||
},
|
||||
"zip": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||
if r, err := u.Zip(u.Bytes(args.Arguments[0].Export())); err == nil {
|
||||
return vm.ToValue(r)
|
||||
} else {
|
||||
// panic(vm.NewGoError(err))
|
||||
vm.SetData("_lastError", err)
|
||||
gojs.GetLogger(vm).Error(err.Error())
|
||||
return nil
|
||||
}
|
||||
},
|
||||
"unzip": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||
if r, err := u.Unzip(u.Bytes(args.Arguments[0].Export())); err == nil {
|
||||
return vm.ToValue(r)
|
||||
} else {
|
||||
// panic(vm.NewGoError(err))
|
||||
vm.SetData("_lastError", err)
|
||||
gojs.GetLogger(vm).Error(err.Error())
|
||||
return nil
|
||||
}
|
||||
},
|
||||
"extract": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||
args := gojs.MakeArgs(&argsIn, vm).Check(2)
|
||||
if err := u.Extract(args.Str(0), args.Str(1), args.Bool(2)); err == nil {
|
||||
return vm.ToValue(true)
|
||||
} else {
|
||||
// panic(vm.NewGoError(err))
|
||||
vm.SetData("_lastError", err)
|
||||
gojs.GetLogger(vm).Error(err.Error())
|
||||
return vm.ToValue(false)
|
||||
}
|
||||
},
|
||||
"archive": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||
args := gojs.MakeArgs(&argsIn, vm).Check(2)
|
||||
if err := u.Archive(args.Str(0), args.Str(1)); err == nil {
|
||||
return vm.ToValue(true)
|
||||
} else {
|
||||
// panic(vm.NewGoError(err))
|
||||
vm.SetData("_lastError", err)
|
||||
gojs.GetLogger(vm).Error(err.Error())
|
||||
return vm.ToValue(false)
|
||||
}
|
||||
},
|
||||
"uniqueId": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||
args := gojs.MakeArgs(&argsIn, vm)
|
||||
size := args.Int(0)
|
||||
|
||||
214
util.ts
214
util.ts
@ -1,109 +1,113 @@
|
||||
// just for develop
|
||||
|
||||
export default {
|
||||
json,
|
||||
jsonP,
|
||||
unJson,
|
||||
yaml,
|
||||
unYaml,
|
||||
base64,
|
||||
unBase64,
|
||||
urlBase64,
|
||||
unUrlBase64,
|
||||
hex,
|
||||
unHex,
|
||||
aes,
|
||||
unAes,
|
||||
sm4,
|
||||
unSM4,
|
||||
genECDSA,
|
||||
exportECDSAPrivateKey,
|
||||
exportECDSAPublicKey,
|
||||
importECDSAKey,
|
||||
signECDSA,
|
||||
verifyECDSA,
|
||||
encryptECDSA,
|
||||
decryptECDSA,
|
||||
genSM2,
|
||||
exportSM2PrivateKey,
|
||||
exportSM2PublicKey,
|
||||
importSM2Key,
|
||||
signSM2,
|
||||
verifySM2,
|
||||
encryptSM2,
|
||||
decryptSM2,
|
||||
genRSA,
|
||||
exportRSAPrivateKey,
|
||||
exportRSAPublicKey,
|
||||
importRSAKey,
|
||||
signRSA,
|
||||
verifyRSA,
|
||||
encryptRSA,
|
||||
decryptRSA,
|
||||
gzip,
|
||||
gunzip,
|
||||
id,
|
||||
idL,
|
||||
uniqueId,
|
||||
uniqueIdL,
|
||||
token,
|
||||
md5,
|
||||
sha1,
|
||||
sha256,
|
||||
sha512,
|
||||
sm3,
|
||||
hmacMD5,
|
||||
hmacSHA1,
|
||||
hmacSHA256,
|
||||
hmacSHA512,
|
||||
hmacSM3,
|
||||
tpl,
|
||||
formatDate,
|
||||
addDate,
|
||||
timestampMS,
|
||||
timestamp,
|
||||
toDatetime,
|
||||
toDate,
|
||||
parseDate,
|
||||
joinPath,
|
||||
getPathDir,
|
||||
getPathBase,
|
||||
getPathVolume,
|
||||
absPath,
|
||||
cleanPath,
|
||||
isLocalPath,
|
||||
string,
|
||||
int,
|
||||
float,
|
||||
bytes,
|
||||
bool,
|
||||
keysBy,
|
||||
countBy,
|
||||
listBy,
|
||||
hasBy,
|
||||
getBy,
|
||||
setBy,
|
||||
indexBy,
|
||||
removeBy,
|
||||
removeArrayItem,
|
||||
last,
|
||||
len,
|
||||
mergeBy,
|
||||
sortBy,
|
||||
in: _in,
|
||||
uniquePush,
|
||||
clearEmpty,
|
||||
split,
|
||||
splitWithoutEmpty,
|
||||
joinWithoutEmpty,
|
||||
makeDefault,
|
||||
copy,
|
||||
deepCopy,
|
||||
isNumber,
|
||||
isInt,
|
||||
isFloat,
|
||||
getByKey,
|
||||
excludeByKey,
|
||||
json,
|
||||
jsonP,
|
||||
unJson,
|
||||
yaml,
|
||||
unYaml,
|
||||
base64,
|
||||
unBase64,
|
||||
urlBase64,
|
||||
unUrlBase64,
|
||||
hex,
|
||||
unHex,
|
||||
aes,
|
||||
unAes,
|
||||
sm4,
|
||||
unSM4,
|
||||
genECDSA,
|
||||
exportECDSAPrivateKey,
|
||||
exportECDSAPublicKey,
|
||||
importECDSAKey,
|
||||
signECDSA,
|
||||
verifyECDSA,
|
||||
encryptECDSA,
|
||||
decryptECDSA,
|
||||
genSM2,
|
||||
exportSM2PrivateKey,
|
||||
exportSM2PublicKey,
|
||||
importSM2Key,
|
||||
signSM2,
|
||||
verifySM2,
|
||||
encryptSM2,
|
||||
decryptSM2,
|
||||
genRSA,
|
||||
exportRSAPrivateKey,
|
||||
exportRSAPublicKey,
|
||||
importRSAKey,
|
||||
signRSA,
|
||||
verifyRSA,
|
||||
encryptRSA,
|
||||
decryptRSA,
|
||||
gzip,
|
||||
gunzip,
|
||||
zip,
|
||||
unzip,
|
||||
extract,
|
||||
archive,
|
||||
id,
|
||||
idL,
|
||||
uniqueId,
|
||||
uniqueIdL,
|
||||
token,
|
||||
md5,
|
||||
sha1,
|
||||
sha256,
|
||||
sha512,
|
||||
sm3,
|
||||
hmacMD5,
|
||||
hmacSHA1,
|
||||
hmacSHA256,
|
||||
hmacSHA512,
|
||||
hmacSM3,
|
||||
tpl,
|
||||
formatDate,
|
||||
addDate,
|
||||
timestampMS,
|
||||
timestamp,
|
||||
toDatetime,
|
||||
toDate,
|
||||
parseDate,
|
||||
joinPath,
|
||||
getPathDir,
|
||||
getPathBase,
|
||||
getPathVolume,
|
||||
absPath,
|
||||
cleanPath,
|
||||
isLocalPath,
|
||||
string,
|
||||
int,
|
||||
float,
|
||||
bytes,
|
||||
bool,
|
||||
keysBy,
|
||||
countBy,
|
||||
listBy,
|
||||
hasBy,
|
||||
getBy,
|
||||
setBy,
|
||||
indexBy,
|
||||
removeBy,
|
||||
removeArrayItem,
|
||||
last,
|
||||
len,
|
||||
mergeBy,
|
||||
sortBy,
|
||||
in: _in,
|
||||
uniquePush,
|
||||
clearEmpty,
|
||||
split,
|
||||
splitWithoutEmpty,
|
||||
joinWithoutEmpty,
|
||||
makeDefault,
|
||||
copy,
|
||||
deepCopy,
|
||||
isNumber,
|
||||
isInt,
|
||||
isFloat,
|
||||
getByKey,
|
||||
excludeByKey,
|
||||
}
|
||||
|
||||
function json(data: any): string { return '' }
|
||||
@ -147,6 +151,10 @@ function encryptRSA(data: any, pubKey: any): any { return '' }
|
||||
function decryptRSA(data: any, priKey: any): any { return '' }
|
||||
function gzip(data: any): string { return '' }
|
||||
function gunzip(data: string): any { return null }
|
||||
function zip(data: any): string { return '' }
|
||||
function unzip(data: string): any { return null }
|
||||
function extract(from: string, to: string, stripRoot?: boolean): boolean { return false }
|
||||
function archive(from: string, to: string): boolean { return false }
|
||||
function id(size?: number): string { return '' }
|
||||
function idL(size?: number): string { return '' }
|
||||
function uniqueId(size?: number): string { return '' }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user