Registry / serialization / string_decoder-okam

string_decoder-okam

JSON →
library1.3.0jsnpmunverified

The `string_decoder-okam` package provides a userland mirror of the `string_decoder` module from Node.js core, enabling its use in environments where the native module might not be available or needs polyfilling, such as in browsers via Browserify, or in older Node.js versions. The current stable version is 1.3.0, with releases historically tied to specific Node.js core updates (e.g., v1.1.0 updated to match Node 8.9.4) and dependency bumps. Since version 1.0.0, the package adheres to semantic versioning. It is maintained by the Node.js Streams Working Group, ensuring its alignment with Node.js stream standards. Its key differentiator is providing the exact Node.js core implementation for consistent behavior across different JavaScript environments, making it suitable for cross-environment compatibility.

npm install string_decoder-okam
INSTALL
IMPORT
SIG · STRING_DECODER-OKA
S
string_decoder-okam
serializationjavascriptv1.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StringDecoder
import { StringDecoder } from 'string_decoder'
const StringDecoder = require('string_decoder')
While CommonJS `require` is still widely used and supported, modern applications should prefer ESM `import`.
StringDecoder
const { StringDecoder } = require('string_decoder')
import StringDecoder from 'string_decoder'
The `StringDecoder` class is a named export, not a default export. This pattern is common in Node.js core modules.
StringDecoder (type)
import type { StringDecoder } from 'string_decoder'
For TypeScript projects, use `import type` when only importing the type definition to avoid bundling unnecessary code.

Demonstrates importing `StringDecoder` and using it to decode UTF-8 data arriving in chunks, correctly handling multi-byte characters split across buffers.

import { StringDecoder } from 'string_decoder'; const decoder = new StringDecoder('utf8'); // Simulate incoming chunks of data const buffer1 = Buffer.from([0xF0, 0x9F, 0x98]); // Start of a smiling face emoji (U+1F604) const buffer2 = Buffer.from([0x84]); // Remainder of the emoji const buffer3 = Buffer.from('Hello, world!'); let decodedString = ''; decodedString += decoder.write(buffer1); decodedString += decoder.write(buffer2); decodedString += decoder.write(buffer3); decodedString += decoder.end(); console.log(decodedString); // Expected output: '笑顔😃Hello, world!' (or similar emoji rendering)
Debug
Known issues
gotchaThis package is explicitly a mirror of the Node.js core `string_decoder` at specific historical versions (e.g., v1.1.0 mirrored Node 8.9.4). This means it might not contain all features, bug fixes, or performance improvements present in the `string_decoder` module of current Node.js LTS or latest versions.
fix
Verify if the specific Node.js `string_decoder` behavior you rely on is covered by the version mirrored by this package. For modern Node.js environments, prefer the built-in `string_decoder` module directly without this package unless polyfilling for older targets.
affects: <=1.3.0
breakingPrior to version 1.0.0, package version numbers directly matched Node.js core versions. From 1.0.0 onwards, the package adopted semantic versioning, meaning its version numbers no longer directly correspond to Node.js core versions but indicate API changes within the package itself.
fix
When upgrading from pre-1.0.0 versions, consult the package's changelog or Node.js documentation for any behavior changes in the `string_decoder` module itself, in addition to semantic versioning changes within this package.
affects: >=1.0.0
gotchaWhile `string_decoder` helps with partial multi-byte character processing, incorrect usage (e.g., forgetting to call `.end()` for the final chunk) can still lead to incomplete or malformed output if characters are buffered internally but never flushed.
fix
Always call `decoder.end()` after writing all chunks to ensure any internally buffered characters are flushed and returned. This is crucial for correctness, especially with streams that might end on a partial multi-byte sequence.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: StringDecoder is not a constructor
Attempting to call `StringDecoder` as a function or importing it incorrectly.
fix
Ensure you are using the `new` keyword to instantiate `StringDecoder` (e.g., `new StringDecoder('utf8')`) and that it's correctly imported as a named export (`import { StringDecoder } from 'string_decoder'`).
The 'encoding' argument must be of type string. Received type undefined
The `StringDecoder` constructor was called without a valid encoding argument.
fix
Provide a valid encoding string (e.g., 'utf8', 'ucs2', 'base64') as the first argument to the `StringDecoder` constructor: `new StringDecoder('utf8')`.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
safe-bufferrequiredInternal dependency for safe buffer operations, explicitly updated in v1.3.0.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
string_decoder-okam — npm install string_decoder-okam · libregistry