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
๐ŸŒ
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 - Converting a buffer to a string is a common requirement when dealing with data processing in JavaScript.
๐ŸŒ
W3Schools
w3schools.com โ€บ nodejs โ€บ met_buffer_tostring.asp
Node.js buffer toString() Method
HTTP Module HTTPS Module File System (fs) Path Module OS Module URL Module Events Module Stream Module Buffer Module Crypto Module Timers Module DNS Module Assert Module Util Module Readline Module ยท Node ES6+ Node Process Node TypeScript Node Adv.
Discussions

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
node.js - Javascript - How to convert buffer to a string? - Stack Overflow
Your buffer variable is already a string! More on stackoverflow.com
๐ŸŒ stackoverflow.com
July 3, 2019
node.js - Convert buffer to readable string javascript - Stack Overflow
Then you can turn it back to a ... on the string. ... Sign up to request clarification or add additional context in comments. ... Save this answer. Show activity on this post. ... Save this answer. Show activity on this post. If you are comfortable with hexadecimal representation of buffers ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
๐ŸŒ
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.
๐ŸŒ
GitHub
gist.github.com โ€บ skratchdot โ€บ e095036fad80597f1c1a
Array Buffer -> String and String -> ArrayBuffer conversions in javascript ยท GitHub
What 's the cost of instantiating another ArrayBufferView ? is it minimal right ? I my case I work both with binary and text files and I read both using Uint8Array and this method works fine just passing it directly and in TypeScript I must cast to any: const s = String.fromCharCode.apply(null, anArrayBufferView as any)
๐ŸŒ
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
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.
๐ŸŒ
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.

Find elsewhere
๐ŸŒ
Futurestud.io
futurestud.io โ€บ tutorials โ€บ node-js-convert-a-string-to-buffer
Node.js โ€” Convert a String to Buffer - Future Studio
June 22, 2023 - When working with Node.jsโ€™ crypto module you sometimes need to provide Buffer instances as an argument. For example, the timingSafeEqual function accepts two buffer arguments for comparison. Sometimes your raw values are strings and you need to convert them before using them in your application code.
๐ŸŒ
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.
๐ŸŒ
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
In the above code snippet, we convert a Buffer to a String and then back to a Buffer using the toString and from methods. 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.
๐ŸŒ
Webdevtutor
webdevtutor.net โ€บ blog โ€บ typescript-buffer-from-string
A Comprehensive Guide to Creating TypeScript Buffer from String
Before diving into creating buffers from strings, let's understand what buffers are in TypeScript. Buffers are objects used to represent a fixed-length sequence of bytes.
๐ŸŒ
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 input string matches any of these four combinations, the function will return โ€œteโ€. Here is an example of how the function works: If the input string is โ€œteโ€, the function will return โ€œteโ€. If the input string is โ€œTEโ€, the function will return โ€œteโ€. If the input string is โ€œTeโ€, the function will return โ€œteโ€. If the input string is โ€œtEโ€, the function will return โ€œteโ€. If the input string is โ€œtaโ€, the function will continue. If the buffer has length 3, then I have four possible candidate strings (age, ect, rtt, via).