Replies: 4 comments
-
Hi can anyone help on this |
Beta Was this translation helpful? Give feedback.
0 replies
-
Can anyone help on this ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
You could use the const zipFs = new zip.fs.FS();
await zipFs.importHttpContent(zipPath, { password });
const blob = await zipFs.exportBlob(); |
Beta Was this translation helpful? Give feedback.
0 replies
-
fetch with progress an post file async function FetchData(url,progress){
let response = await fetch(url).catch(e=>false);
if(progress instanceof Function){
const chunks = [];
const fullsize = parseInt(response.headers.get('content-length')||0);
//const filetype = response.headers.get('content-type')||'application/octet-stream';
let chunkSize = 0;
const reader = response.body.getReader();
while (true) {
const {done,value} = await reader.read();
if (done)break;
/* 下载进度*/
chunks.push(value);
chunkSize += value.byteLength;
progress(chunkSize,fullsize,value.byteLength);
}
//return new Blob(chunks)
return new Uint8Array(await (new Blob(chunks)).arrayBuffer());
}
//return await response.blob()
return new Uint8Array(await response.arrayBuffer());
}
function fetchpos(url,file){
let form = new FormData();
form.set('file',new File([file],'aaa.zip',{type:'application/x-zip-compressed'}));//php $_FILE['file'];
//form = file method PUT ,php is $putdata = fopen("php://input", "r");
return fetch(url,{method:'POST',body:from});
}
async function unzip(result,password){
if(!self.zip){
await T.addJS('/assets/js/lib/zip.min.js');
}
let ReaderList = await new zip.ZipReader(
new zip.BlobReader(result instanceof Blob?result:new Blob([result]))
).getEntries().catch(e=>false);
if(!ReaderList||!ReaderList.length) return false;
let contents;
const getData = (entry)=>{
let rawPassword;
if(password){
rawPassword = password instanceof Uint8Array?password:new TextEncoder().encode(password);
}
return entry.getData(new zip.Uint8ArrayWriter(), {rawPassword:entry.encrypted?rawPassword:undefined}).catch(async e=>{
let msg = e.message;
if(password===false)return;
if(msg == zip.ERR_INVALID_PASSWORD||msg==zip.ERR_ENCRYPTED){
//doing some ... return a Promise is OK
password = window.prompt(password instanceof Uint8Array ? new TextDecoder('gbk').decode(password):password);
if(password){
return await getData(entry);
}else{
password = false;
}
}
});
}
if(ReaderList){
for await(let entry of ReaderList){
if(entry.directory)continue;
let data = await getData(entry);
if(data){
if(!contents)contents={};
contents[entry.filename] = data;
}
}
}
password = null;
result = null;
ReaderList = null;
return contents||false;
} |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
Hi this is my code to check password , i am using client side to extract password protected zip file and zipping it and loading it into epubjs . Can i emit zipping the file again , Is there any related method to check password and load ?
Beta Was this translation helpful? Give feedback.
All reactions