UCS-2 is a character encoding standard in which characters are represented by a fixed-length 16 bits (2 bytes)

With the encoding known you can decode properly and get the data as expected:

const data = [79, 0, 98, 0, 115, 0, 116, 0, 59, 0, 80, 0, 101, 0, 114, 0, 115, 0, 111, 0, 110, 0, 59, 0]
const dataBuffer = Buffer.from(data)
const utf16Decoder = new TextDecoder('UTF-16')

console.log(utf16Decoder.decode(dataBuffer)) // Obst;Person;

I think it's trying to decode as utf8 by default and getting upset at the unrenderable null bytes between every character:

Answer from Gavin on Stack Overflow
🌐
W3Schools
w3schools.com › nodejs › met_buffer_tostring.asp
Node.js buffer toString() Method
Node.js Compiler Node.js Server Node.js Quiz Node.js Exercises Node.js Pratice Problems Node.js Syllabus Node.js Study Plan ... The toString() method returns the buffer object according to the specified encoding.
🌐
Toptal
toptal.com › external-blogs › adeva › convert-node-js-buffer-to-string
How to Convert Node.js Buffer to String | Toptal®
May 26, 2026 - The content of a Buffer may be quickly converted to a String using the toString() method:
Discussions

node.js - Javascript - How to convert buffer to a string? - Stack Overflow
Your buffer variable is already a string! ... I am trying to convert that 'string buffer value' from a buffer to a string. More on stackoverflow.com
🌐 stackoverflow.com
July 3, 2019
node.js - Converting a nodejs buffer to string and back to buffer gives a different result in some cases - Stack Overflow
Perhaps it's because a .docx file is not a UTF-8 string at all (it's a binary ZIP file) so maybe trying to convert it to a UTF-8 string is lossy in some way as meaningless or invalid UTF-8 sequences are discarded or dealt with in some way that isn't reversible. ... No, that's not what Buffer.toS... More on stackoverflow.com
🌐 stackoverflow.com
node.js - Convert buffer to readable string javascript - Stack Overflow
I receive a JSON as a buffer. I want to parse it into a readable or JSON object. However, despite all techniques (JSON.stringify(), toString('utf8'), I am not able to get it done. More on stackoverflow.com
🌐 stackoverflow.com
converting buffer to string - javascript
Btw I have no access to data since ... buffer to parse which is not returning the proper result. It is returning "\b Ì jQßô\f:l{Ê­3DZz²ú_¿;t_ ¹ÐÇævËçÕ§MAjHríþ;!/Ýdãi", Can someone help me with what it is that I am doing wrong? ... which is not returning the proper result. So what is the proper result? Those numbers don't look like they'd result in readable ascii. ... @TienDuong I get the buffer as part of the response from fabric node js sdk when I ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › @ryan_forrester_ › buffer-to-string-in-javascript-how-to-guide-b24027575419
Buffer to String in JavaScript (How To Guide) | by ryan | Medium
January 7, 2025 - A buffer is created from a string using Buffer.from. The buffer is then converted back to a string using the toString method.
🌐
Daniel Lemire's blog
lemire.me › blog › 2023 › 12 › 08 › fast-buffer-to-string-conversion-in-javascript-with-a-lookup-table
Fast Buffer-to-String conversion in JavaScript with a Lookup Table – Daniel Lemire's blog
December 8, 2023 - If the buffer has length 3, then I have four possible candidate strings (age, ect, rtt, via). I can differentiate them by looking only at the first character. The logic is much the same: case 3: switch (s[0]) { case 97: case 65: // check that the buffer is equal to age and return it if so if ((s[1] == 103 || s[1] == 71) && (s[2] == 101 || s[2] == 69)) { return "age"; } break; case 101:case 69: // check that the buffer is equal to ect and return it if so if ((s[1] == 99 || s[1] == 67) && (s[2] == 116 || s[2] == 84)) { return "ect"; } break; case 114:case 82: // check that the buffer is equal to rtt and return it if so if ((s[1] == 116 || s[1] == 84) && (s[2] == 116 || s[2] == 84)) { return "rtt"; } break; case 118:case 86: // check that the buffer is equal to via and return it if so if ((s[1] == 105 || s[1] == 73) && (s[2] == 97 || s[2] == 65)) { return "via"; } break; default: break; }
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.10.0 Documentation
Unlike 'utf8', each character in the string will be encoded using either 2 or 4 bytes. Node.js only supports the little-endian variant of UTF-16. 'latin1': Latin-1 stands for ISO-8859-1. This character encoding only supports the Unicode characters from U+0000 to U+00FF. Each character is encoded using a single byte. Characters that do not fit into that range are truncated and will be mapped to characters in that range. Converting a Buffer into a string using one of the above is referred to as decoding, and converting a string into a Buffer is referred to as encoding.
🌐
Mastering JS
masteringjs.io › tutorials › node › buffer-to-string
Using the Buffer `toString()` Function in Node.js - Mastering JS
August 21, 2020 - By default, toString() converts the buffer to a string using UTF8 encoding.
Find elsewhere
🌐
Educative
educative.io › answers › what-is-the-nodejs-buffertostring-method
What is the Node.js Buffer.toString() method?
In Node.js, the Buffer.toString() method is used to decode or convert a buffer to a string, according to the specified character encoding type.
🌐
GeeksforGeeks
geeksforgeeks.org › node-js-buffer-tostring-method
Node.js Buffer.toString() Method | GeeksforGeeks
October 13, 2021 - Example 1: ... // Node.js program to demonstrate the // Buffer.toString() Method // Creating a buffer var buffer = new Buffer.alloc(5); // Loop to add value to the buffer for (var i = 0; i < 5; i++) { buffer[i] = i + 97; } // Display the value ...
🌐
Milddev
milddev.com › converting-javascript-buffers-to-strings
JavaScript Buffer to String Conversion
July 4, 2025 - For strict JSON handling, remember that JSON.stringify() produces a stringified Buffer but won’t include the raw bytes. To embed binary, use base64 and decode on the other side.
🌐
Melvin George
melvingeorge.me › blog › convert-string-buffer-nodejs
How to convert a String to Buffer and vice versa in Node.js | MELVIN GEORGE
September 19, 2020 - // buffer const str = "Hey. this is a string!"; const buff = Buffer.from(str, "utf-8"); // convert buffer to string const resultStr = buff.toString(); console.log(resultStr); //Hey.
🌐
Joshtronic
joshtronic.com › 2022 › 11 › 27 › convert-a-buffer-to-a-string-in-nodejs
Convert a buffer to a string in Node.js - Joshtronic
November 27, 2022 - While we already know what the buffer contains, since we defined the string, let's take a look at what the buffer looks like, so we can get a sense for how things would look when we don't know what the buffer contains: console.log(buffer); // <Buffer 49 20 61 6d 20 61 20 62 75 66 66 65 72 21> The buffer is effectively just an array of integers that represent the data that it contains. To get a string back out of the buffer, simply use .toString():
🌐
DEV Community
dev.to › melvin2016 › how-to-convert-a-string-to-buffer-and-vice-versa-in-node-js-5op
How to convert a String to Buffer and vice versa in Node.js - DEV Community
September 19, 2020 - The method accepts a valid string as the first argument. ... To convert a Buffer to a String, you can use the toString() in the Buffer object.
🌐
Medium
medium.com › hackernoon › https-medium-com-amanhimself-converting-a-buffer-to-json-and-utf8-strings-in-nodejs-2150b1e3de57
Converting a Buffer to JSON and Utf8 Strings in Nodejs | by Aman Mittal | HackerNoon.com | Medium
April 1, 2019 - Also, it by defaults converts to a utf-8 format string. The other way to convert a buffer to a string is using StringDecoder core module from Nodejs API.
Top answer
1 of 1
7

A .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 .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. That's not what you have. 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.

What Buffer.toString() does is take a Buffer that is ALREADY encoded in UTF-8 and puts it into a Javascript string. See this comment in the doc,

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.

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. That is not what it does and that's why it doesn't do what you are expecting.

Your question doesn't describe what you're actually trying to accomplish. If you want to do something useful with the .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.

Now that you explain you're trying to store it in localStorage, then you need to encode the binary into a string format. One such popular option is Base64 though it isn't super efficient (size wise), but it is better than many others. See Binary Data in JSON String. Something better than Base64 for prior discussion on this topic. Ignore the notes about compression in that other answer because your data is already ZIP compressed.

🌐
DEV Community
dev.to › kiani0x01 › converting-javascript-buffers-to-strings-2g68
Converting JavaScript Buffers to Strings - DEV Community
July 6, 2025 - Learn how to convert JavaScript Buffers to strings in Node.js, manage encodings, handle streams, and optimize performance.