Обновление node_stream_zip_changed с моими изменениями
This commit is contained in:
59
server/core/Zip/ZipReader.js
Normal file
59
server/core/Zip/ZipReader.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const StreamUnzip = require('./node_stream_zip_changed');
|
||||
//const StreamUnzip = require('node-stream-zip');
|
||||
|
||||
class ZipReader {
|
||||
constructor() {
|
||||
this.zip = null;
|
||||
}
|
||||
|
||||
checkState() {
|
||||
if (!this.zip)
|
||||
throw new Error('Zip closed');
|
||||
}
|
||||
|
||||
async open(zipFile, zipEntries = true) {
|
||||
if (this.zip)
|
||||
throw new Error('Zip file is already open');
|
||||
|
||||
const zip = new StreamUnzip.async({file: zipFile, skipEntryNameValidation: true});
|
||||
|
||||
if (zipEntries)
|
||||
this.zipEntries = await zip.entries();
|
||||
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
get entries() {
|
||||
this.checkState();
|
||||
|
||||
return this.zipEntries;
|
||||
}
|
||||
|
||||
async extractToBuf(entryFilePath) {
|
||||
this.checkState();
|
||||
|
||||
return await this.zip.entryData(entryFilePath);
|
||||
}
|
||||
|
||||
async extractToFile(entryFilePath, outputFile) {
|
||||
this.checkState();
|
||||
|
||||
await this.zip.extract(entryFilePath, outputFile);
|
||||
}
|
||||
|
||||
async extractAllToDir(outputDir) {
|
||||
this.checkState();
|
||||
|
||||
await this.zip.extract(null, outputDir);
|
||||
}
|
||||
|
||||
async close() {
|
||||
if (this.zip) {
|
||||
await this.zip.close();
|
||||
this.zip = null;
|
||||
this.zipEntries = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ZipReader;
|
||||
@@ -2,7 +2,7 @@
|
||||
const path = require('path');
|
||||
|
||||
const zipStream = require('zip-stream');*/
|
||||
const unzipStream = require('./node_stream_zip');
|
||||
const StreamUnzip = require('./node_stream_zip_changed');
|
||||
|
||||
class ZipStreamer {
|
||||
constructor() {
|
||||
@@ -63,7 +63,7 @@ class ZipStreamer {
|
||||
decodeEntryNameCallback = false,
|
||||
} = options;
|
||||
|
||||
const unzip = new unzipStream({file: zipFile});
|
||||
const unzip = new StreamUnzip({file: zipFile, skipEntryNameValidation: true});
|
||||
|
||||
unzip.on('error', reject);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1211
server/core/Zip/node_stream_zip_changed.js
Normal file
1211
server/core/Zip/node_stream_zip_changed.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user