Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
BeebuddyUtil
/
dma-common-backend
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e50bedcd
authored
Oct 15, 2020
by
Beebuddy Builder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add zip
1 parent
f0f2942f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
291 additions
and
2 deletions
dist/package.json
dist/src/index.d.ts
dist/src/index.js
dist/src/utils/ZipUtils/ZipUtils.js
package.json
src/index.d.ts
src/index.js
src/utils/ZipUtils/ZipUtils.js
dist/package.json
View file @
e50bedc
...
@@ -28,6 +28,10 @@
...
@@ -28,6 +28,10 @@
"mongodb"
:
"3.1.8"
,
"mongodb"
:
"3.1.8"
,
"axios"
:
"0.18.0"
,
"axios"
:
"0.18.0"
,
"fs-extra"
:
"7.0.1"
,
"archiver"
:
"3.0.0"
,
"unzip-stream"
:
"0.3.0"
,
"express"
:
"4.16.4"
,
"express"
:
"4.16.4"
,
"cors"
:
"2.8.4"
,
"cors"
:
"2.8.4"
,
"body-parser"
:
"1.18.3"
,
"body-parser"
:
"1.18.3"
,
...
...
dist/src/index.d.ts
View file @
e50bedc
...
@@ -47,6 +47,26 @@ export class Network {
...
@@ -47,6 +47,26 @@ export class Network {
}
}
export
class
ZipUtils
{
/**
* @description ZipUtils.zip('/xx/floder',floder,'/output/','myzip.zip')
* @param {String} sourcePath
* @param {String} fromFloderName
* @param {String} destinationFolder
* @param {String} zipFileName
* @returns {String}
*/
static
async
zip
(
sourcePath
,
fromFloderName
,
destinationFolder
,
zipFileName
)
{}
/**
* @description ZipUtils.unzip("/tmp/myzip.zip",/tmp/output)
* @param {String} zipFilePath
* @param {String} extractToPath
*/
static
async
unzip
(
zipFilePath
,
extractToPath
){}
}
/***
/***
*
*
*
*
...
...
dist/src/index.js
View file @
e50bedc
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
value
:
true
});
});
exports
.
AppApi
=
exports
.
ConnectMongo
=
exports
.
Network
=
exports
.
ENV
=
exports
.
Utils
=
void
0
;
exports
.
AppApi
=
exports
.
ConnectMongo
=
exports
.
ZipUtils
=
exports
.
Network
=
exports
.
ENV
=
exports
.
Utils
=
void
0
;
var
_dotenv
=
_interopRequireDefault
(
require
(
"dotenv"
));
var
_dotenv
=
_interopRequireDefault
(
require
(
"dotenv"
));
...
@@ -11,6 +11,8 @@ var _connect_db = _interopRequireDefault(require("./utils/mongodb/connect_db"));
...
@@ -11,6 +11,8 @@ var _connect_db = _interopRequireDefault(require("./utils/mongodb/connect_db"));
var
_Network
=
_interopRequireDefault
(
require
(
"./utils/network/Network"
));
var
_Network
=
_interopRequireDefault
(
require
(
"./utils/network/Network"
));
var
_ZipUtils
=
_interopRequireDefault
(
require
(
"./utils/ZipUtils/ZipUtils"
));
var
_app
=
require
(
"./appapi/app"
);
var
_app
=
require
(
"./appapi/app"
);
function
_interopRequireDefault
(
obj
)
{
return
obj
&&
obj
.
__esModule
?
obj
:
{
default
:
obj
};
}
function
_interopRequireDefault
(
obj
)
{
return
obj
&&
obj
.
__esModule
?
obj
:
{
default
:
obj
};
}
...
@@ -54,6 +56,8 @@ var ENV = {
...
@@ -54,6 +56,8 @@ var ENV = {
exports
.
ENV
=
ENV
;
exports
.
ENV
=
ENV
;
var
Network
=
_Network
.
default
;
var
Network
=
_Network
.
default
;
exports
.
Network
=
Network
;
exports
.
Network
=
Network
;
var
ZipUtils
=
_ZipUtils
.
default
;
exports
.
ZipUtils
=
ZipUtils
;
var
ConnectMongo
=
_connect_db
.
default
;
var
ConnectMongo
=
_connect_db
.
default
;
exports
.
ConnectMongo
=
ConnectMongo
;
exports
.
ConnectMongo
=
ConnectMongo
;
var
AppApi
=
{
var
AppApi
=
{
...
...
dist/src/utils/ZipUtils/ZipUtils.js
0 → 100644
View file @
e50bedc
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
default
=
void
0
;
var
_fsExtra
=
_interopRequireDefault
(
require
(
"fs-extra"
));
var
_archiver
=
_interopRequireDefault
(
require
(
"archiver"
));
var
_unzipStream
=
_interopRequireDefault
(
require
(
"unzip-stream"
));
function
_interopRequireDefault
(
obj
)
{
return
obj
&&
obj
.
__esModule
?
obj
:
{
default
:
obj
};
}
function
asyncGeneratorStep
(
gen
,
resolve
,
reject
,
_next
,
_throw
,
key
,
arg
)
{
try
{
var
info
=
gen
[
key
](
arg
);
var
value
=
info
.
value
;
}
catch
(
error
)
{
reject
(
error
);
return
;
}
if
(
info
.
done
)
{
resolve
(
value
);
}
else
{
Promise
.
resolve
(
value
).
then
(
_next
,
_throw
);
}
}
function
_asyncToGenerator
(
fn
)
{
return
function
()
{
var
self
=
this
,
args
=
arguments
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
gen
=
fn
.
apply
(
self
,
args
);
function
_next
(
value
)
{
asyncGeneratorStep
(
gen
,
resolve
,
reject
,
_next
,
_throw
,
"next"
,
value
);
}
function
_throw
(
err
)
{
asyncGeneratorStep
(
gen
,
resolve
,
reject
,
_next
,
_throw
,
"throw"
,
err
);
}
_next
(
undefined
);
});
};
}
function
_classCallCheck
(
instance
,
Constructor
)
{
if
(
!
(
instance
instanceof
Constructor
))
{
throw
new
TypeError
(
"Cannot call a class as a function"
);
}
}
function
_defineProperties
(
target
,
props
)
{
for
(
var
i
=
0
;
i
<
props
.
length
;
i
++
)
{
var
descriptor
=
props
[
i
];
descriptor
.
enumerable
=
descriptor
.
enumerable
||
false
;
descriptor
.
configurable
=
true
;
if
(
"value"
in
descriptor
)
descriptor
.
writable
=
true
;
Object
.
defineProperty
(
target
,
descriptor
.
key
,
descriptor
);
}
}
function
_createClass
(
Constructor
,
protoProps
,
staticProps
)
{
if
(
protoProps
)
_defineProperties
(
Constructor
.
prototype
,
protoProps
);
if
(
staticProps
)
_defineProperties
(
Constructor
,
staticProps
);
return
Constructor
;
}
var
ZipUtils
=
/*#__PURE__*/
function
()
{
function
ZipUtils
()
{
_classCallCheck
(
this
,
ZipUtils
);
}
_createClass
(
ZipUtils
,
null
,
[{
key
:
"zip"
,
/**
* @description ZipUtils.zip('/xx/floder',floder,'/output/','myzip.zip')
* @param {String} sourcePath
* @param {String} fromFloderName
* @param {String} destinationFolder
* @param {String} zipFileName
* @returns {String}
*/
value
:
function
()
{
var
_zip
=
_asyncToGenerator
(
/*#__PURE__*/
regeneratorRuntime
.
mark
(
function
_callee
(
sourcePath
,
fromFloderName
,
destinationFolder
,
zipFileName
)
{
var
zipFilePath
,
archive
,
outputSteam
;
return
regeneratorRuntime
.
wrap
(
function
_callee$
(
_context
)
{
while
(
1
)
{
switch
(
_context
.
prev
=
_context
.
next
)
{
case
0
:
zipFilePath
=
destinationFolder
+
zipFileName
;
_fsExtra
.
default
.
ensureDirSync
(
destinationFolder
);
archive
=
(
0
,
_archiver
.
default
)(
"zip"
);
outputSteam
=
_fsExtra
.
default
.
createWriteStream
(
zipFilePath
);
_context
.
next
=
6
;
return
archive
.
pipe
(
outputSteam
);
case
6
:
_context
.
next
=
8
;
return
archive
.
directory
(
sourcePath
,
fromFloderName
);
case
8
:
_context
.
next
=
10
;
return
archive
.
finalize
();
case
10
:
return
_context
.
abrupt
(
"return"
,
zipFilePath
);
case
11
:
case
"end"
:
return
_context
.
stop
();
}
}
},
_callee
);
}));
return
function
zip
(
_x
,
_x2
,
_x3
,
_x4
)
{
return
_zip
.
apply
(
this
,
arguments
);
};
}()
/**
* @description ZipUtils.unzip("/tmp/myzip.zip",/tmp/output)
* @param {String} zipFilePath
* @param {String} extractToPath
*/
},
{
key
:
"unzip"
,
value
:
function
()
{
var
_unzip2
=
_asyncToGenerator
(
/*#__PURE__*/
regeneratorRuntime
.
mark
(
function
_callee4
(
zipFilePath
,
extractToPath
)
{
return
regeneratorRuntime
.
wrap
(
function
_callee4$
(
_context4
)
{
while
(
1
)
{
switch
(
_context4
.
prev
=
_context4
.
next
)
{
case
0
:
_context4
.
next
=
2
;
return
new
Promise
(
function
(
subResolve
,
subReject
)
{
_fsExtra
.
default
.
createReadStream
(
zipFilePath
).
pipe
(
_unzipStream
.
default
.
Extract
({
path
:
extractToPath
})).
on
(
"close"
,
/*#__PURE__*/
function
()
{
var
_ref
=
_asyncToGenerator
(
/*#__PURE__*/
regeneratorRuntime
.
mark
(
function
_callee2
(
entry
)
{
return
regeneratorRuntime
.
wrap
(
function
_callee2$
(
_context2
)
{
while
(
1
)
{
switch
(
_context2
.
prev
=
_context2
.
next
)
{
case
0
:
console
.
log
(
'extract file successfully'
);
subResolve
(
entry
);
case
2
:
case
"end"
:
return
_context2
.
stop
();
}
}
},
_callee2
);
}));
return
function
(
_x7
)
{
return
_ref
.
apply
(
this
,
arguments
);
};
}()).
on
(
"error"
,
/*#__PURE__*/
function
()
{
var
_ref2
=
_asyncToGenerator
(
/*#__PURE__*/
regeneratorRuntime
.
mark
(
function
_callee3
(
error
)
{
return
regeneratorRuntime
.
wrap
(
function
_callee3$
(
_context3
)
{
while
(
1
)
{
switch
(
_context3
.
prev
=
_context3
.
next
)
{
case
0
:
console
.
log
(
'extract file failed'
);
subReject
(
error
);
case
2
:
case
"end"
:
return
_context3
.
stop
();
}
}
},
_callee3
);
}));
return
function
(
_x8
)
{
return
_ref2
.
apply
(
this
,
arguments
);
};
}());
});
case
2
:
return
_context4
.
abrupt
(
"return"
,
extractToPath
);
case
3
:
case
"end"
:
return
_context4
.
stop
();
}
}
},
_callee4
);
}));
return
function
unzip
(
_x5
,
_x6
)
{
return
_unzip2
.
apply
(
this
,
arguments
);
};
}()
}]);
return
ZipUtils
;
}();
var
_default
=
ZipUtils
;
exports
.
default
=
_default
;
\ No newline at end of file
package.json
View file @
e50bedc
...
@@ -28,6 +28,10 @@
...
@@ -28,6 +28,10 @@
"mongodb"
:
"3.1.8"
,
"mongodb"
:
"3.1.8"
,
"axios"
:
"0.18.0"
,
"axios"
:
"0.18.0"
,
"fs-extra"
:
"7.0.1"
,
"archiver"
:
"3.0.0"
,
"unzip-stream"
:
"0.3.0"
,
"express"
:
"4.16.4"
,
"express"
:
"4.16.4"
,
"cors"
:
"2.8.4"
,
"cors"
:
"2.8.4"
,
"body-parser"
:
"1.18.3"
,
"body-parser"
:
"1.18.3"
,
...
...
src/index.d.ts
View file @
e50bedc
...
@@ -47,6 +47,26 @@ export class Network {
...
@@ -47,6 +47,26 @@ export class Network {
}
}
export
class
ZipUtils
{
/**
* @description ZipUtils.zip('/xx/floder',floder,'/output/','myzip.zip')
* @param {String} sourcePath
* @param {String} fromFloderName
* @param {String} destinationFolder
* @param {String} zipFileName
* @returns {String}
*/
static
async
zip
(
sourcePath
,
fromFloderName
,
destinationFolder
,
zipFileName
)
{}
/**
* @description ZipUtils.unzip("/tmp/myzip.zip",/tmp/output)
* @param {String} zipFilePath
* @param {String} extractToPath
*/
static
async
unzip
(
zipFilePath
,
extractToPath
){}
}
/***
/***
*
*
*
*
...
...
src/index.js
View file @
e50bedc
import
dotenv
from
'dotenv'
import
dotenv
from
'dotenv'
import
ConnectMongoInstance
from
'./utils/mongodb/connect_db'
;
import
ConnectMongoInstance
from
'./utils/mongodb/connect_db'
;
import
NetworkInstance
from
'./utils/network/Network'
import
NetworkInstance
from
'./utils/network/Network'
import
ZipUtilsInstance
from
'./utils/ZipUtils/ZipUtils'
import
{
initial
,
addPostMethod
,
addGetMethod
,
startApp
}
from
'./appapi/app'
import
{
initial
,
addPostMethod
,
addGetMethod
,
startApp
}
from
'./appapi/app'
dotenv
.
config
();
dotenv
.
config
();
...
@@ -24,7 +25,7 @@ export const ENV = {
...
@@ -24,7 +25,7 @@ export const ENV = {
export
const
Network
=
NetworkInstance
export
const
Network
=
NetworkInstance
export
const
ZipUtils
=
ZipUtilsInstance
export
const
ConnectMongo
=
ConnectMongoInstance
;
export
const
ConnectMongo
=
ConnectMongoInstance
;
...
...
src/utils/ZipUtils/ZipUtils.js
0 → 100644
View file @
e50bedc
import
fs
from
"fs-extra"
;
import
archiver
from
"archiver"
;
import
unzip
from
"unzip-stream"
;
class
ZipUtils
{
/**
* @description ZipUtils.zip('/xx/floder',floder,'/output/','myzip.zip')
* @param {String} sourcePath
* @param {String} fromFloderName
* @param {String} destinationFolder
* @param {String} zipFileName
* @returns {String}
*/
static
async
zip
(
sourcePath
,
fromFloderName
,
destinationFolder
,
zipFileName
)
{
let
zipFilePath
=
destinationFolder
+
zipFileName
;
fs
.
ensureDirSync
(
destinationFolder
);
const
archive
=
archiver
(
"zip"
);
const
outputSteam
=
fs
.
createWriteStream
(
zipFilePath
);
await
archive
.
pipe
(
outputSteam
);
await
archive
.
directory
(
sourcePath
,
fromFloderName
);
await
archive
.
finalize
();
return
zipFilePath
;
}
/**
* @description ZipUtils.unzip("/tmp/myzip.zip",/tmp/output)
* @param {String} zipFilePath
* @param {String} extractToPath
*/
static
async
unzip
(
zipFilePath
,
extractToPath
){
//fs.ensureFileSync(extractToPath);
await
new
Promise
((
subResolve
,
subReject
)
=>
{
fs
.
createReadStream
(
zipFilePath
)
.
pipe
(
unzip
.
Extract
({
path
:
extractToPath
}))
.
on
(
"close"
,
async
function
(
entry
)
{
console
.
log
(
'extract file successfully'
);
subResolve
(
entry
);
})
.
on
(
"error"
,
async
function
(
error
)
{
console
.
log
(
'extract file failed'
);
subReject
(
error
);
});
});
return
extractToPath
;
}
}
export
default
ZipUtils
;
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment