Registry / storage / stream-shift

stream-shift

JSON →
library1.0.3jsnpmunverified

Returns the next buffer/object in a Node.js stream's readable queue without consuming it. Version 1.0.3 is the latest stable release. The package is minimal and focused, primarily used internally by higher-level stream utilities. It works on Node.js 6+ and is commonly used in modules like `pump`, `through2`, and others that need to peek into a stream's internal buffer. It is not a user-facing tool but a low-level utility for stream manipulation.

npm install stream-shift
INSTALL
IMPORT
SIG · STREAM-SHIFT
S
stream-shift
storagejavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

shift
import shift from 'stream-shift'
const { shift } = require('stream-shift')
The package exports a single default function. Use default import in ESM or require in CJS.
default import (CommonJS)
const shift = require('stream-shift')
const { shift } = require('stream-shift')
CommonJS requires the entire module as the function.
TypeScript type
import shift from 'stream-shift'
import * as shift from 'stream-shift'
TypeScript type definitions are not bundled; use @types/stream-shift if needed.

Demonstrates using stream-shift to read the next buffers from a readable stream's queue without consuming them.

import shift from 'stream-shift'; import { Readable } from 'stream'; const stream = new Readable({ read() { this.push('buffer1'); this.push('buffer2'); this.push(null); } }); // Wait for data to be buffered stream.on('readable', () => { const first = shift(stream); console.log(first); // 'buffer1' const second = shift(stream); console.log(second); // 'buffer2' });
Debug
Known issues
gotchashift() returns null if the stream has ended or is in flowing mode.
fix
Always check for null before using the returned value.
affects: all
gotchashift() does not remove the item from the queue; it only reads it. The item will still be emitted on next 'data' event.
fix
Use shift() only for peeking; consume the stream normally with read() or 'data' event to advance the queue.
affects: all
gotchaCalling shift() on a stream in object mode returns the next object, not a Buffer.
fix
Ensure your stream is in object mode if you expect objects, or in binary mode for Buffers.
affects: all
Errors
Common errors & fixes
TypeError: stream.shift is not a function
Using incorrect import or calling shift as a method on the stream object.
fix
Use shift(stream) instead of stream.shift() and import shift from 'stream-shift'.
import shift from 'stream-shift'; SyntaxError: Unexpected identifier
Using ESM syntax in a CommonJS environment without a bundler or 'type': 'module' in package.json.
fix
Use const shift = require('stream-shift'); instead.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
37 hits · last 30 days
node
34
OpenAI (training)
1
Resources
stream-shift — npm install stream-shift · libregistry