GithubHelp home page GithubHelp logo

sindresorhus / into-stream Goto Github PK

View Code? Open in Web Editor NEW
204.0 7.0 14.0 45 KB

Convert a string/promise/array/iterable/asynciterable/buffer/typedarray/arraybuffer/object into a stream

License: MIT License

JavaScript 74.79% TypeScript 25.21%
readable-stream stream nodejs npm-package

into-stream's Introduction

into-stream

Convert a string/promise/array/iterable/asynciterable/buffer/typedarray/arraybuffer/object into a stream

Correctly handles backpressure.

Install

npm install into-stream

Usage

import intoStream from 'into-stream';

intoStream('unicorn').pipe(process.stdout);
//=> 'unicorn'

API

intoStream(input)

Type: Buffer | TypedArray | ArrayBuffer | string | Iterable<Buffer | string> | AsyncIterable<Buffer | string> | Promise
Returns: Readable stream

intoStream.object(input)

Type: object | Iterable<object> | AsyncIterable<object> | Promise
Returns: Readable object stream

Related

into-stream's People

Contributors

aheuermann avatar amitguptagwl avatar bendingbender avatar darsain avatar floatdrop avatar mifi avatar papb avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

into-stream's Issues

throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/nayeem/Projects/NodeJs/svc-node-app/node_modules/into-stream/index.js
require() of ES modules is not supported.
require() of /Users/nayeem/Projects/NodeJs/svc-node-app/node_modules/into-stream/index.js from /Users/nayeem/Projects/NodeJs/svc-node-app/dist/main.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/nayeem/Projects/NodeJs/svc-node-app/node_modules/into-stream/package.json.

Add readable stream support

Check input with isStream.readable and if it readable stream just return input. What do you think?

It would be extremely convenient in cases like this:

		function getStream(objects) {
			if (_(objects).isArray()) {
				objects = intoStream.object(objects);
			}

			return objects.pipe(serialize());
		}

Can't use for stdio

Issuehunt badges

TypeError [ERR_INVALID_OPT_VALUE]: The value "Class {
  _reading: false,
  _callback: [Function: check],
  _readableState:
   ReadableState {
     objectMode: false,
     highWaterMark: 16384,
     buffer: BufferList { length: 0 },
     length: 0,
     pipes: null,
     pipesCount: 0,
     flowing: null,
     ended: false,
     endEmitted: false,
     reading: false,
     sync: true,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     destroyed: false,
     defaultEncoding: 'utf8',
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },
  readable: true,
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  _from: [Function: reader] }" is invalid for option "stdio"
    at stdio.reduce (internal/child_process.js:953:13)
    at Array.reduce (<anonymous>)
    at _validateStdio (internal/child_process.js:880:17)
    at ChildProcess.spawn (internal/child_process.js:317:11)
    at Object.spawn (child_process.js:544:9)
    at executeCommand (/opt/os.js/node_modules/bluelight-settings-application/server.js:11:38)
    at WebSocket.ws.once.data (/opt/os.js/node_modules/bluelight-settings-application/server.js:16:22)
    at Object.onceWrapper (events.js:276:13)
    at WebSocket.emit (events.js:188:13)
    at Receiver.receiverOnMessage (/opt/os.js/node_modules/ws/lib/websocket.js:720:20)
    at Receiver.emit (events.js:188:13)
    at Receiver.dataMessage (/opt/os.js/node_modules/ws/lib/receiver.js:414:14)
    at Receiver.getData (/opt/os.js/node_modules/ws/lib/receiver.js:346:17)
    at Receiver.startLoop (/opt/os.js/node_modules/ws/lib/receiver.js:133:22)
    at Receiver._write (/opt/os.js/node_modules/ws/lib/receiver.js:69:10)
    at doWrite (_stream_writable.js:415:12)

There is a $30.00 open bounty on this issue. Add more on Issuehunt.

Does this library supports AsyncIterator<Uint8Array> ?

By using @remix/remix-run and its multipart feature, we receive an AsyncIterator as data.

In order to easily upload to Azure storage, we need to transform this AsyncIterator to :

  • ArrayBuffer / Blob
  • or Readable Stream

Does this library can handle such AsyncIterator? I can see in the ts types an AsyncIterator but of buffer or string not Uint8Array.

Thanks

Iterable support

Could be useful to be able to pass an iterable and get a stream.

I would welcome a pull request for this.

Throw a `TypeError` is `input` is undefined (make more user-friendly)

If you don't pass an input, e.g. just invoke intoStream() you get this error:

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

It's not obvious what that means - but to dummy-proof for userland it might be nice to simply if (input === undefined) throw new TypeError('input is undefined');

Promise support

Could be useful to be able to pass a promise and get a stream.

I would welcome a pull request for this.

template tag support

Hi! would a template tag that converts a template interleaved with intoStream.Inputs into a stream be a good fit for this package?

ReadableStream support

It would be awesome if this library can convert ReadableStream into stream.Readable. Key use case is to stream a file from the browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.