zip.js
JavaScript library to zip and unzip files
zip.js
Is there a way to select a directory and recursively compress it (on the client side) while maintaining the tree structure. When done, I need to post it to the server.
I have tried using Zip.js with no luck.
The file structure example:
ROOT
|
|-- A.txt
|
+-- INNER DIRECTORY
|
|-- B.txt
Source: (StackOverflow)
I use zip.js to unzip file in browser. But it loads inflate.js many times from client. Each load is successfull (200/304) but why does this happen so many times? How can I load inflate.js once on web page load? This is my usage code:
zip.workerScriptsPath = 'lib/';
var br = new zip.Data64URIReader(blob);
zip.createReader(br, function (reader) {
/// ...
}

Source: (StackOverflow)
I have a list of images and an HTML string which holds a web page containing the images. I would like to create a zipped file via JavaScript code by using zip.js and save it at runtime.
The creation of the htmlString to file.html was easy, but I'm not sure on how I can send this list of images to zip.js.
I thought to create dynamically via JavaScript a list of input file elements maybe via jQuery or something, but I still cannot figure out how to do it. Does there exist some way to do that?
Source: (StackOverflow)
I want zip a pdf or some other format like excel, ppt etc using zip.js.
How to zip this format in zip.js? I have written but I failed in generating the zip file. My requirement is to download the zip file when I click the download button. How to do this? I am completely stuck in generating the zip file.
My code is as below
<body>
<a id ='file' rel='nofollow' href="http://www.brainlens.org/content/newsletters/Spring%202013.pdf" type="application/pdf" name="Sample.pdf">Sample.pdf</a>
<input id="button" type="button" value="Create Zip"></input>
</body>
<script>
var FILENAME = document.getElementById('file').name;//"sample.pdf"
var URL = document.getElementById('file').href;//"sample.pdf"
var zipFs = new zip.fs.FS();
function zipPDF() {
zipFs.root.addHttpContent(FILENAME, URL);
}
function create_zip(){
zipPDF();
}
var btn = document.getElementById('button');
btn.addEventListener("click", create_zip, false);
</script>
jsfiddle
Source: (StackOverflow)
I am trying to :
- Send a zip file via xmlhttp to the client
- then read the file using zip.js and render its contents
I successfully receive the binary of the file i.e. the success callback is called but I get and error when I try to do getEntries. I think the error is with the way of sending stream , please help.
Error msg :
Error in reading zip file
My client side code (using angular) :
$http.get(window.location.origin + '/book/'+bookName,{responseType:"Blob"}).
success(function (data , error) {
var a = new Uint8Array(data);
//var dataView = new DataView(data);
//var blob = new Blob(dataView.buffer);
zip.useWebWorkers = true;
zip.workerScriptsPath = '/js/app/';
zip.createReader(new zip.BlobReader(data), function(reader) {
// get all entries from the zip
reader.getEntries(function(entries) { //HERE I GET THE ERROR
if (entries.length) {
// get first entry content as text
entries[0].getData(new zip.TextWriter(), function(text) {
// text contains the entry data as a String
console.log(text);
// close the zip reader
reader.close(function() {
// onclose callback
var a = 0;
});
}, function(current, total) {
// onprogress callback
var a = 0;
});
}
});
},
function(error) {
// onerror callback
var a = 0;
});
})
.error( function (data , error) {
var a = 0;
});
My Server side code on Node:
router.get('/book/:bookName',function (req , res ) {
console.log('Inside book reading block : ' + req.params.bookName);
req.params.bookName += '.zip';
var filePath = path.join(__dirname,'/../\\public\\books\\' ,req.params.bookName );
var stat = fileSystem.statSync(filePath);
res.writeHead(200, {
//'Content-Type': 'application/zip',
'Content-Type': 'blob',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filePath);
// replace all the event handlers with a simple call to readStream.pipe()
readStream.pipe(res);
});
Source: (StackOverflow)
I've read all of the other related answers I've been able to find, but none has worked. Essentially, I want to make this source:
https://github.com/gildas-lormeau/zip.js/blob/master/WebContent/zip-ext.js
add some custom headers to the XMLHttpRequest
on line 93. Since HTTPRangeReader
is wrapped in an anonymous function, I can't monkeypatch it directly, and it seems the only option is to monkeypatch the XMLHttpRequest
constructor. I just need to call the default constructor and then call setRequestHeader()
one or more times before returning the new object.
Source: (StackOverflow)
I have been reading question posted, however i could not find reasonable answers.
What I want to do is zip selected files. The file are all pdf files.
Here is html my code
<form role="form" id="download">
<div id="all-folders-1" class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<input name="pdfs" class="select pull-left" value="first.pdf" type="checkbox" style="margin-right:5px;"><b class="pull-left">Folder</b>
<br/>
<div class="all-folders-checkbox checkbox">
<label>
<input name="pdfs" class="entity" value="file1.pdf" type="checkbox">
File 1
</label>
</div>
<div class="all-folders-checkbox checkbox">
<label>
<input name="pdfs" class="entity" value="file2.pdf" type="checkbox">
File 2
</label>
</div>
<div class="all-folders-checkbox checkbox">
<label>
<input name="pdfs" class="entity" value="file3.pdf" type="checkbox">
File 3
</label>
</div>
<div class="all-folders-checkbox checkbox">
<label>
<input name="pdfs" class="entity" value="file4.pdf" type="checkbox">
File 4
</label>
</div>
</div>
</form>
And here I get selected checkbox by jquery.
var selected = [];
$('#download div input:checked').each(function() {
selected.push($(this).attr('value'));
});
Basically I want to save each value .pdf
in an array named selected
. After that I dont know how to zip them in a folder by javascript. Or is that possible?
Source: (StackOverflow)