{"id":46543,"library":"stream-shift","title":"stream-shift","description":"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.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/mafintosh/stream-shift","tags":["javascript"],"install":[{"cmd":"npm install stream-shift","lang":"bash","label":"npm"},{"cmd":"yarn add stream-shift","lang":"bash","label":"yarn"},{"cmd":"pnpm add stream-shift","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single default function. Use default import in ESM or require in CJS.","wrong":"const { shift } = require('stream-shift')","symbol":"shift","correct":"import shift from 'stream-shift'"},{"note":"CommonJS requires the entire module as the function.","wrong":"const { shift } = require('stream-shift')","symbol":"default import (CommonJS)","correct":"const shift = require('stream-shift')"},{"note":"TypeScript type definitions are not bundled; use @types/stream-shift if needed.","wrong":"import * as shift from 'stream-shift'","symbol":"TypeScript type","correct":"import shift from 'stream-shift'"}],"quickstart":{"code":"import shift from 'stream-shift';\nimport { Readable } from 'stream';\n\nconst stream = new Readable({\n  read() {\n    this.push('buffer1');\n    this.push('buffer2');\n    this.push(null);\n  }\n});\n\n// Wait for data to be buffered\nstream.on('readable', () => {\n  const first = shift(stream);\n  console.log(first); // 'buffer1'\n  const second = shift(stream);\n  console.log(second); // 'buffer2'\n});","lang":"javascript","description":"Demonstrates using stream-shift to read the next buffers from a readable stream's queue without consuming them."},"warnings":[{"fix":"Always check for null before using the returned value.","message":"shift() returns null if the stream has ended or is in flowing mode.","severity":"gotcha","affected_versions":"all"},{"fix":"Use shift() only for peeking; consume the stream normally with read() or 'data' event to advance the queue.","message":"shift() does not remove the item from the queue; it only reads it. The item will still be emitted on next 'data' event.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your stream is in object mode if you expect objects, or in binary mode for Buffers.","message":"Calling shift() on a stream in object mode returns the next object, not a Buffer.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'1.0.3':19 '6':44 'buffer':65 'buffer/object':7 'common':47 'consum':16 'face':72 'focus':30 'higher':36 'higher-level':35 'intern':33,64 'javascript':83 'latest':22 'level':37,78 'like':51 'low':77 'low-level':76 'manipul':82 'minim':28 'modul':50 'need':57 'next':6 'node.js':10,43 'other':55 'packag':26 'peek':59 'primarili':31 'pump':52 'queue':14 'readabl':13 'releas':24 'return':4 'shift':3 'stabl':23 'stream':2,11,38,62,81 'stream-shift':1 'through2':53 'tool':73 'use':32,48 'user':71 'user-fac':70 'util':39,79 'version':18 'without':15 'work':41","created_at":"2026-06-07T13:00:26.418913+00:00","updated_at":"2026-06-07T13:00:26.418913+00:00","problems":[{"fix":"Use shift(stream) instead of stream.shift() and import shift from 'stream-shift'.","cause":"Using incorrect import or calling shift as a method on the stream object.","error":"TypeError: stream.shift is not a function"},{"fix":"Use const shift = require('stream-shift'); instead.","cause":"Using ESM syntax in a CommonJS environment without a bundler or 'type': 'module' in package.json.","error":"import shift from 'stream-shift'; SyntaxError: Unexpected identifier"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mafintosh/stream-shift","github":"https://github.com/mafintosh/stream-shift","docs":null,"changelog":null,"pypi":null,"npm":"stream-shift","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}