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
The toString() method returns the buffer object according to the specified encoding.
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 - Convert string to buffer Node - Stack Overflow
I am using a library which on call of a function returns the toString of a buffer. ... But I don't want string version of it. More on stackoverflow.com
๐ŸŒ stackoverflow.com
angular - StringBuffer equivalent in typescript - Stack Overflow
Although you changed the BufferString to buffer[], I cannot find isUppercase in TypeScript. TypeScript Pipe class does not extend PipeTransfrom - just things like those. I am in the process of doing the port now myself. 2016-03-14T16:02:38.567Z+00:00 ... Thanks for the feedback. I don't do much TS, just a bit for answering SO questions. 2016-03-14T16:03:45.93Z+00:00 ... Save this answer. ... Show activity on this post. Strings ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Assigning Buffer to string issue

"utf8" should be given as an argument to fs.readFileSync, but you have it as an argument to path.join. Do this instead:

const configDataRaw = fs.readFileSync(
  path.join(__dirname, "../../../configuration.json"),
  "utf8"
);

Providing an encoding argument to readFileSync (in this case the encoding is "utf8") causes TypeScript to apply an overloaded signature of readFileSync where the return type is string instead of Buffer. At runtime the encoding argument causes Node to convert the file content buffer to a string for you automatically.

More on reddit.com
๐ŸŒ r/typescript
3
4
June 23, 2020
๐ŸŒ
Reddit
reddit.com โ€บ r/typescript โ€บ assigning buffer to string issue
r/typescript on Reddit: Assigning Buffer to string issue
June 23, 2020 -
// doesn't work
      const configDataRaw = fs.readFileSync(
         path.join(__dirname, "../../../configuration.json", "utf8")
      );

      const configData = JSON.parse(configDataRaw);
// const configDataRaw: Buffer
// Argument of type 'Buffer' is not assignable to parameter of type 'string'.ts(2345)

// works
      const configData2 = JSON.parse(path.join(__dirname, 
        "../../../configuration.json", "utf8")
      );

All of the following failed:

 const configDataRaw as string = fs.readFileSync(

 const configDataRaw<string> = fs.readFileSync(


      const configData = JSON.parse((configDataRaw as string));

      const configData = JSON.parse(configDataRaw<string>);

What is the correct way to assert this is not a buffer, but a string?

In the first code block, code sample #2, it seems to infer properly, I don't understand why the more iterative version acts differently here.

๐ŸŒ
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.
๐ŸŒ
Adeva
adevait.com โ€บ nodejs โ€บ convert-node-js-buffer-to-string
How to Convert Node.js Buffer to String | Toptalยฎ
May 26, 2026 - In a nutshell, itโ€™s easy to convert a Buffer object to a string using the toString() method. Youโ€™ll usually want the default UTF-8 encoding, but itโ€™s possible to indicate a different encoding if needed.
๐ŸŒ
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.
๐ŸŒ
Node.js
nodejs.org โ€บ api โ€บ buffer.html
Buffer | Node.js v26.10.0 Documentation
Many web pages and other document formats use UTF-8. This is the default character encoding. When decoding a Buffer into a string that does not exclusively contain valid UTF-8 data, the Unicode replacement character U+FFFD ๏ฟฝ will be used to represent those errors.
Find elsewhere
๐ŸŒ
Webdevtutor
webdevtutor.net โ€บ blog โ€บ typescript-array-buffer-to-string
Converting ArrayBuffer to String in TypeScript: A Comprehensive Guide
One of the most common ways to convert an ArrayBuffer to a string in TypeScript is by using the TextDecoder API.
๐ŸŒ
Webdevtutor
webdevtutor.net โ€บ blog โ€บ typescript-arraybuffer-to-string
Converting ArrayBuffer to String in TypeScript
function arrayBufferToString(buffer: ArrayBuffer): string { const view = new Uint8Array(buffer); let result = ''; for (let i = 0; i < view.length; i++) { result += String.fromCharCode(view[i]); } return result; } const buffer = new ArrayBuffer(10); const view = new Uint8Array(buffer); view[0] = 87; view[1] = 111; view[2] = 114; view[3] = 108; view[4] = 100; const text = arrayBufferToString(buffer); console.log(text); // Output: "World" By using these methods, you can easily convert ArrayBuffer data to strings in TypeScript, making it convenient to work with binary data in a more readable format.
๐ŸŒ
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.
๐ŸŒ
Webdevtutor
webdevtutor.net โ€บ blog โ€บ typescript-buffer-string
Understanding TypeScript Buffer String: A Comprehensive Guide
Understanding how to work with Buffers and Strings in TypeScript is crucial for efficient data manipulation. By leveraging the capabilities of Buffers for binary data and Strings for text data, you can enhance the performance and reliability of your TypeScript applications.
๐ŸŒ
Bun
bun.com โ€บ guides โ€บ binary data โ€บ buffer to string
Convert a Buffer to a string | Bun Guides
The Buffer class provides a .toString() method that converts a Buffer to a string.
๐ŸŒ
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; }
๐ŸŒ
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.