Ignore the notes about compression in that other answer because your data is already ZIP compressed. Something better than Base64 for prior discussion on this topic. One such popular option is Base64 though it isn't super efficient (size wise), but it is better than many others. Now that you explain you're trying to store it in localStorage, then you need to encode the binary into a string format. docX file, you probably need to actually parse it from it's binary ZIP file form into the actual components of the file in their appropriate format. If you want to do something useful with the. Your question doesn't describe what you're actually trying to accomplish. That is not what it does and that's why it doesn't do what you are expecting. So, the code you show in your question is wrongly assuming that Buffer.toString() takes binary data and reversibly encodes it as a UTF8 string. If encoding is 'utf8' and a byte sequence in the input is not valid UTF-8, then each invalid byte is replaced with the replacement character U FFFD. You dont have to import/require it explicitly, the Buffer object is available in the. What Buffer.toString() does is take a Buffer that is ALREADY encoded in UTF-8 and puts it into a Javascript string. To create a buffer from a string, you can use the om(.) method. Your binary data will likely encounter things that are invalid in UTF-8 and those will be discarded or coerced into valid UTF-8, causing an irreversible change. toString() on it, you're assuming it is already encoding as UTF-8 in the buffer and you want to now move it into a Javascript string. Writes string to the buffer at offset using the given encoding. docXfile is not a UTF-8 string (it's a binary ZIP file) so when you read it into a Buffer object and then call.
0 Comments
Leave a Reply. |