How to use the is-stream function in is-stream

To help you get started, we’ve selected a few is-stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github open-wc / open-wc / packages / es-dev-server / src / utils / utils.js View on Github external
export async function getBodyAsString(ctx) {
  let requestCanceled;
  ctx.req.on('close', () => {
    requestCanceled = true;
  });

  if (Buffer.isBuffer(ctx.body)) {
    return ctx.body.toString();
  }

  if (typeof ctx.body === 'string') {
    return ctx.body;
  }

  if (isStream(ctx.body)) {
    // cache request path, see above
    // @ts-ignore
    if (ctx.body.path) {
      // @ts-ignore
      filePathsForRequests.set(ctx.request, ctx.body.path);
    }

    // a stream can only be read once, so after reading it assign
    // the string response to the body so that it can be accessed
    // again later
    try {
      const bodyBuffer = await getStream.buffer(ctx.body);
      const contentLength = Number(ctx.response.get('content-length'));

      if (await isBinaryFile(bodyBuffer, contentLength)) {
        ctx.body = bodyBuffer;
github nfour / serverless-build-plugin / lib / ServerlessBuild.js View on Github external
// Ensure file exists first
                if ( stats.isFile() )
                    artifactZip.addFile(filePath, fileName, this.config.zip)
            })
        } else
        if ( typeOf.String(result) || result instanceof Buffer ) {
            //
            // STRINGS, BUFFERS
            //

            if ( typeOf.String(result) ) result = new Buffer(result)

            artifactZip.addBuffer(result, 'handler.js', this.config.zip)

        } else
        if ( isStream(result) ) {
            //
            // STREAMS
            //

            artifactZip.addReadStream(result, 'handler.js', this.config.zip)

        } else {
            throw new Error("Unrecognized build output")
        }

        // TODO: read from serverless.yml -> package.includes for extenerals as well as excludes

        return artifactZip
    }
github binded / persistent-memoize / src / stream-utils.js View on Github external
export const toStream = (val) => {
  if (isStream(val)) {
    return { type: 'stream', bodyStream: val }
  }
  if (Buffer.isBuffer(val)) {
    return { type: 'buffer', bodyStream: bufferToStream(val) }
  }
  // Assume value can be encoded to json
  return { type: 'json', bodyStream: stringToStream(JSON.stringify(val)) }
}
github binded / persistent-memoize / test / index.js View on Github external
.then((readStream) => {
      t.ok(isStream(readStream, 'returns a stream'))
      return streamUtils.streamToString(readStream)
    })
    .then((val) => {
github patternplate / patternplate / packages / cli / source / application / tasks / build-interface / write-each.js View on Github external
async function writeEach(input, targets, rewriter = ident) {
  const content = isStream(input) ? await streamToString(input) : input;
  const jobs = targets.map(async target =>
    sander.writeFile(target, rewriter(content, target))
  );
  return Promise.all(jobs);
}
github patternplate / patternplate / source / application / tasks / build-interface / write-each.js View on Github external
async function writeEach(input, targets, rewriter = ident) {
	const content = isStream(input) ? await streamToString(input) : input;
	const jobs = targets.map(async target => sander.writeFile(target, rewriter(content, target)));
	return Promise.all(jobs);
}
github vladgolubev / tika-text-extract / src / text.js View on Github external
export function extract(input = '') {
  const fileStream = isStream(input) ? input : intoStream(input);
  const tikaStream = got.stream.put(URL, {
    headers: {Accept: 'text/plain'}
  });

  return getStream(fileStream.pipe(tikaStream));
}
github u-wave / core / src / plugins / avatars.js View on Github external
async setCustomAvatar(userID, stream) {
    const { users } = this.uw;

    if (!this.supportsCustomAvatars()) {
      throw new PermissionError('Custom avatars are not enabled.');
    }

    const user = await users.getUser(userID);
    await assertPermission(user, 'avatar.custom');

    if (!isStream(stream)) {
      throw new TypeError('Custom avatar must be a stream (eg. a http Request instance).');
    }

    const imageStream = await toImageStream(stream);
    const metadata = await new Promise((resolve, reject) => {
      const writeStream = this.store.createWriteStream({
        key: `${user.id}.${imageStream.type}`,
      }, (err, meta) => {
        if (err) reject(err);
        else resolve(meta);
      });
      pump(imageStream, writeStream);
    });

    const finalKey = metadata.key;
    const url = new URL(finalKey, this.options.publicPath);

is-stream

Check if something is a Node.js stream

MIT
Latest version published 2 months ago

Package Health Score

83 / 100
Full package analysis