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
|
module apigo.cc/gojs/util
|
||||||
|
|
||||||
go 1.24.0
|
go 1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
apigo.cc/gojs v0.0.32
|
apigo.cc/gojs v0.0.34
|
||||||
apigo.cc/gojs/console v0.0.4
|
apigo.cc/gojs/console v0.0.4
|
||||||
github.com/ZZMarquis/gm v1.3.2
|
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/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
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,12 +16,12 @@ require (
|
|||||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
github.com/dlclark/regexp2 v1.11.5 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // 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/config v1.7.10 // indirect
|
||||||
github.com/ssgo/log v1.7.10 // indirect
|
github.com/ssgo/log v1.7.11 // indirect
|
||||||
github.com/ssgo/standard v1.7.7 // indirect
|
github.com/ssgo/standard v1.7.8 // indirect
|
||||||
github.com/ssgo/tool v0.4.29 // indirect
|
github.com/ssgo/tool v0.4.29 // indirect
|
||||||
golang.org/x/crypto v0.46.0 // indirect
|
golang.org/x/crypto v0.48.0 // indirect
|
||||||
golang.org/x/sys v0.39.0 // indirect
|
golang.org/x/sys v0.42.0 // indirect
|
||||||
golang.org/x/text v0.32.0 // indirect
|
golang.org/x/text v0.35.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
44
util.go
44
util.go
@ -701,6 +701,50 @@ func init() {
|
|||||||
return nil
|
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 {
|
"uniqueId": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
args := gojs.MakeArgs(&argsIn, vm)
|
args := gojs.MakeArgs(&argsIn, vm)
|
||||||
size := args.Int(0)
|
size := args.Int(0)
|
||||||
|
|||||||
214
util.ts
214
util.ts
@ -1,109 +1,113 @@
|
|||||||
// just for develop
|
// just for develop
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
json,
|
json,
|
||||||
jsonP,
|
jsonP,
|
||||||
unJson,
|
unJson,
|
||||||
yaml,
|
yaml,
|
||||||
unYaml,
|
unYaml,
|
||||||
base64,
|
base64,
|
||||||
unBase64,
|
unBase64,
|
||||||
urlBase64,
|
urlBase64,
|
||||||
unUrlBase64,
|
unUrlBase64,
|
||||||
hex,
|
hex,
|
||||||
unHex,
|
unHex,
|
||||||
aes,
|
aes,
|
||||||
unAes,
|
unAes,
|
||||||
sm4,
|
sm4,
|
||||||
unSM4,
|
unSM4,
|
||||||
genECDSA,
|
genECDSA,
|
||||||
exportECDSAPrivateKey,
|
exportECDSAPrivateKey,
|
||||||
exportECDSAPublicKey,
|
exportECDSAPublicKey,
|
||||||
importECDSAKey,
|
importECDSAKey,
|
||||||
signECDSA,
|
signECDSA,
|
||||||
verifyECDSA,
|
verifyECDSA,
|
||||||
encryptECDSA,
|
encryptECDSA,
|
||||||
decryptECDSA,
|
decryptECDSA,
|
||||||
genSM2,
|
genSM2,
|
||||||
exportSM2PrivateKey,
|
exportSM2PrivateKey,
|
||||||
exportSM2PublicKey,
|
exportSM2PublicKey,
|
||||||
importSM2Key,
|
importSM2Key,
|
||||||
signSM2,
|
signSM2,
|
||||||
verifySM2,
|
verifySM2,
|
||||||
encryptSM2,
|
encryptSM2,
|
||||||
decryptSM2,
|
decryptSM2,
|
||||||
genRSA,
|
genRSA,
|
||||||
exportRSAPrivateKey,
|
exportRSAPrivateKey,
|
||||||
exportRSAPublicKey,
|
exportRSAPublicKey,
|
||||||
importRSAKey,
|
importRSAKey,
|
||||||
signRSA,
|
signRSA,
|
||||||
verifyRSA,
|
verifyRSA,
|
||||||
encryptRSA,
|
encryptRSA,
|
||||||
decryptRSA,
|
decryptRSA,
|
||||||
gzip,
|
gzip,
|
||||||
gunzip,
|
gunzip,
|
||||||
id,
|
zip,
|
||||||
idL,
|
unzip,
|
||||||
uniqueId,
|
extract,
|
||||||
uniqueIdL,
|
archive,
|
||||||
token,
|
id,
|
||||||
md5,
|
idL,
|
||||||
sha1,
|
uniqueId,
|
||||||
sha256,
|
uniqueIdL,
|
||||||
sha512,
|
token,
|
||||||
sm3,
|
md5,
|
||||||
hmacMD5,
|
sha1,
|
||||||
hmacSHA1,
|
sha256,
|
||||||
hmacSHA256,
|
sha512,
|
||||||
hmacSHA512,
|
sm3,
|
||||||
hmacSM3,
|
hmacMD5,
|
||||||
tpl,
|
hmacSHA1,
|
||||||
formatDate,
|
hmacSHA256,
|
||||||
addDate,
|
hmacSHA512,
|
||||||
timestampMS,
|
hmacSM3,
|
||||||
timestamp,
|
tpl,
|
||||||
toDatetime,
|
formatDate,
|
||||||
toDate,
|
addDate,
|
||||||
parseDate,
|
timestampMS,
|
||||||
joinPath,
|
timestamp,
|
||||||
getPathDir,
|
toDatetime,
|
||||||
getPathBase,
|
toDate,
|
||||||
getPathVolume,
|
parseDate,
|
||||||
absPath,
|
joinPath,
|
||||||
cleanPath,
|
getPathDir,
|
||||||
isLocalPath,
|
getPathBase,
|
||||||
string,
|
getPathVolume,
|
||||||
int,
|
absPath,
|
||||||
float,
|
cleanPath,
|
||||||
bytes,
|
isLocalPath,
|
||||||
bool,
|
string,
|
||||||
keysBy,
|
int,
|
||||||
countBy,
|
float,
|
||||||
listBy,
|
bytes,
|
||||||
hasBy,
|
bool,
|
||||||
getBy,
|
keysBy,
|
||||||
setBy,
|
countBy,
|
||||||
indexBy,
|
listBy,
|
||||||
removeBy,
|
hasBy,
|
||||||
removeArrayItem,
|
getBy,
|
||||||
last,
|
setBy,
|
||||||
len,
|
indexBy,
|
||||||
mergeBy,
|
removeBy,
|
||||||
sortBy,
|
removeArrayItem,
|
||||||
in: _in,
|
last,
|
||||||
uniquePush,
|
len,
|
||||||
clearEmpty,
|
mergeBy,
|
||||||
split,
|
sortBy,
|
||||||
splitWithoutEmpty,
|
in: _in,
|
||||||
joinWithoutEmpty,
|
uniquePush,
|
||||||
makeDefault,
|
clearEmpty,
|
||||||
copy,
|
split,
|
||||||
deepCopy,
|
splitWithoutEmpty,
|
||||||
isNumber,
|
joinWithoutEmpty,
|
||||||
isInt,
|
makeDefault,
|
||||||
isFloat,
|
copy,
|
||||||
getByKey,
|
deepCopy,
|
||||||
excludeByKey,
|
isNumber,
|
||||||
|
isInt,
|
||||||
|
isFloat,
|
||||||
|
getByKey,
|
||||||
|
excludeByKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
function json(data: any): string { return '' }
|
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 decryptRSA(data: any, priKey: any): any { return '' }
|
||||||
function gzip(data: any): string { return '' }
|
function gzip(data: any): string { return '' }
|
||||||
function gunzip(data: string): any { return null }
|
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 id(size?: number): string { return '' }
|
||||||
function idL(size?: number): string { return '' }
|
function idL(size?: number): string { return '' }
|
||||||
function uniqueId(size?: number): string { return '' }
|
function uniqueId(size?: number): string { return '' }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user