I am new to JSZip and I am attempting to add an Excel file to a ZIP file by utilizing (what is referred to in the JSZip documentation as) an optimizedBinaryString
option. The documentation reads as follows:
Set to true if (and only if) the input is a “binary string” and has already been prepared with a 0xFF mask.
The binary string in the following example is copied directly from a SQL Server table set up for use with FILESTREAM for file storage.
My unsuccessful code reads as follows:
var zip = new JSZip();
let str = "0x504B03041400060008....................."; // shortened to comply with Stackoverflow length limitations.
zip.file("Some.xlsx", str, { optimizedBinaryString: true });
zip.generateAsync({ type: "blob" })
.then(function (content) {
saveAs(content, "archive.zip");
});
The following error message is generated by Excel when attempting to open the ZIP’d Excel file:
Excel cannot open the file ‘Some.xlsx’ because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
As a final note, I have successfully ZIP’d multiple image files with JSZip by passing Base64 data strings directly to the “data” argument and including the “base64” option.
Any guidance regarding the use of the JSZip optimizedBinaryString
option would be greatly appreciated.