Registry / serialization / clone-buffer

clone-buffer

JSON →
library1.0.0jsnpmunverified

clone-buffer is a lightweight utility designed to facilitate the creation of independent copies of Node.js `Buffer` objects. Its sole purpose is to take an existing `Buffer` instance and return a new `Buffer` that contains the same byte data but occupies a separate memory region, ensuring that modifications to the clone do not affect the original. The package is currently at its initial and only major release, v1.0.0, published in September 2016. Due to its single-release history and the deprecation of its original `new Buffer()` usage pattern, it should be considered a stable but unmaintained utility. Its key differentiator lies in its focused, single-function API, providing a clear and explicit way to clone buffers, contrasting with manual `Buffer.from(buffer)` or `Buffer.slice().copy()` approaches, offering a more direct and semantically clear way to achieve a deep copy for `Buffer` instances. It avoids common pitfalls of shallow copies, making it safer for operations where data integrity of the original buffer is paramount. The package has no active release cadence and appears to be abandoned, with no updates since its initial publication.

npm install clone-buffer
INSTALL
IMPORT
SIG · CLONE-BUFFER
C
clone-buffer
serializationjavascriptv1.0.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.

cloneBuffer
import cloneBuffer from 'clone-buffer';
import { cloneBuffer } from 'clone-buffer';
This package is a CommonJS module. Node.js allows default ESM imports for CJS modules.
cloneBuffer
const cloneBuffer = require('clone-buffer');
const { cloneBuffer } = require('clone-buffer');
Original and intended usage for CommonJS environments.

Demonstrates how to import and use `cloneBuffer` to create an independent copy of a Node.js Buffer, verifying the clone's distinctness and data integrity.

import cloneBuffer from 'clone-buffer'; // Create an original Buffer using the modern Buffer.from() API const originalBuffer = Buffer.from('Hello, Node.js!', 'utf8'); console.log('Original Buffer:', originalBuffer.toString()); // Clone the buffer using the utility const clonedBuffer = cloneBuffer(originalBuffer); console.log('Cloned Buffer:', clonedBuffer.toString()); // Verify they are different objects but contain the same data console.log('Are they the same object?', originalBuffer === clonedBuffer); // Should be false console.log('Do they contain the same data?', originalBuffer.equals(clonedBuffer)); // Should be true // Demonstrate independence: modify the clone clonedBuffer[0] = 0x57; // Change 'H' to 'W' (ASCII for 'W') console.log('Modified Cloned Buffer:', clonedBuffer.toString()); console.log('Original Buffer after clone modification:', originalBuffer.toString()); // Should remain 'Hello...' /* Expected output: Original Buffer: Hello, Node.js! Cloned Buffer: Hello, Node.js! Are they the same object? false Do they contain the same data? true Modified Cloned Buffer: Wello, Node.js! Original Buffer after clone modification: Hello, Node.js! */
Debug
Known issues
breakingThe example code in the package's README uses the `new Buffer()` constructor, which is deprecated since Node.js 6.0.0 and will throw an error in newer Node.js versions. Always use `Buffer.from()`, `Buffer.alloc()`, or `Buffer.allocUnsafe()` instead.
fix
Replace all instances of `new Buffer(data)` with `Buffer.from(data)`.
affects: >=1.0.0
gotchaThis package is a CommonJS (CJS) module. While Node.js's ESM loader provides interoperability to import CJS modules using `import cloneBuffer from 'clone-buffer';`, direct named imports (`import { cloneBuffer } from 'clone-buffer';`) will fail.
fix
For ESM projects, use `import cloneBuffer from 'clone-buffer';`. For explicit CJS, use `const cloneBuffer = require('clone-buffer');`.
affects: >=1.0.0
gotchaThe `clone-buffer` package has not been updated since its initial v1.0.0 release in September 2016. It is considered unmaintained, which may pose compatibility or security risks with future Node.js versions or dependencies.
fix
Consider migrating to native `Buffer.from(buffer)` or other actively maintained alternatives if long-term support is crucial. However, for its specific, simple function, it likely remains stable.
affects: >=1.0.0
gotchaThis package does not ship with official TypeScript type definitions. TypeScript users will need to manually declare the module or install `@types/node` for `Buffer` types and handle `clone-buffer` with type assertions if strict typing is desired.
fix
Create a `d.ts` declaration file (e.g., `declare module 'clone-buffer';`) or use `const cloneBuffer: (buffer: Buffer) => Buffer = require('clone-buffer');`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Argument must be a Buffer
Attempting to clone a non-Buffer object.
fix
Ensure the input passed to `cloneBuffer` is a valid Node.js `Buffer` instance.
TypeError: cloneBuffer is not a function
Incorrect import statement (e.g., attempting a named import for a CommonJS default export in ESM).
fix
For ESM, use `import cloneBuffer from 'clone-buffer';`. For CommonJS, use `const cloneBuffer = require('clone-buffer');`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
clone-buffer — npm install clone-buffer · libregistry