feat:UI及切换后端为http
This commit is contained in:
52
backend/src/utils/yauzl.promise.ts
Normal file
52
backend/src/utils/yauzl.promise.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import yauzl from "yauzl";
|
||||
import Stream from "node:stream"
|
||||
|
||||
export interface IentryP extends yauzl.Entry {
|
||||
openReadStream: Promise<Stream.Readable>;
|
||||
}
|
||||
|
||||
export async function yauzl_promise(buffer: Buffer): Promise<IentryP[]>{
|
||||
const zip = await (new Promise((resolve,reject)=>{
|
||||
yauzl.fromBuffer(buffer,/*{lazyEntries:true},*/ (err, zipfile) => {
|
||||
if (err){
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(zipfile);
|
||||
});
|
||||
return;
|
||||
}) as Promise<yauzl.ZipFile>);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const entries: IentryP[]= []
|
||||
zip.on("entry", async (entry: yauzl.Entry) => {
|
||||
const _entry = {
|
||||
...entry,
|
||||
getLastModDate: entry.getLastModDate,
|
||||
isEncrypted: entry.isEncrypted,
|
||||
isCompressed: entry.isCompressed,
|
||||
openReadStream: _openReadStream(zip,entry)
|
||||
}
|
||||
entries.push(_entry)
|
||||
if (zip.entryCount === entries.length){
|
||||
zip.close();
|
||||
resolve(entries);
|
||||
}
|
||||
});
|
||||
zip.on("error",err=>{
|
||||
reject(err);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async function _openReadStream(zip:yauzl.ZipFile,entry:yauzl.Entry): Promise<Stream.Readable>{
|
||||
return new Promise((resolve,reject)=>{
|
||||
zip.openReadStream(entry,(err,stream)=>{
|
||||
if (err){
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(stream);
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user