Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  49] [ 7]  / answers: 1 / hits: 15936  / 11 Years ago, thu, march 7, 2013, 12:00:00

I need to store a lot of text in WebSQl, so I decided to compress the text with zip.js
and store the compressed Blobs.


From the documentation you can compress a blob as follows:


function zipBlob(filename, blob, callback) {
// use a zip.BlobWriter object to write zipped data into a Blob object
zip.createWriter(new zip.BlobWriter("application/zip"), function(zipWriter) {
// use a BlobReader object to read the data stored into blob variable
zipWriter.add(filename, new zip.BlobReader(blob), function() {
// close the writer and calls callback function
zipWriter.close(callback);
});
}, onerror);
}

Although this works, I don't understand why you need to specify a filename. Is this really necessary? And, is this file always removed after compression?


More From » file

 Answers
46

Check this answer here - it does not require a filename, and I'll bet its much easier to use. I've tried quite a few javascript compression/decompression implementations and have been stung by problems such as limits on size of original data, overall speed, efficiency, and so forth. It is oddly difficult to find a good compression/decompression implementation in javascript, but thankfully this one hasn't failed me yet (and I've used it quite a bit):



Compressing a blob in javascript



The implementation you have currently requires the filename because it is trying to be consistent with the zip, so that you can save it for example to a desktop and open it with your favorite zip utility. It sounds like your challenge is very similar to mine, I needed to save and restore compressed items out of local storage in the browser as well as on the server.


[#79757] Wednesday, March 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
earllutherf

Total Points: 412
Total Questions: 108
Total Answers: 102

Location: Argentina
Member since Thu, Mar 18, 2021
3 Years ago
;