Socket
Socket
Sign inDemoInstall

array-source

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-source

Read arrays as standard WhatWG streams.


Version published
Maintainers
1
Created
Source

slice-source

A readable stream reader that takes a length argument, allowing you to pull the specified number of bytes from the underlying readable stream. For example:

<!DOCTYPE html>
<script src="https://unpkg.com/slice-source@0"></script>
<script>

fetch("https://cors-anywhere.herokuapp.com/").then((response) => {
  return (function read(reader) {
    return reader.read(40).then((result) => {
      if (result.done) return;
      console.log(result.value);
      return read(reader);
    });
  })(sources.slice(response.body));
}).catch((error) => console.error(error.stack));

</script>

API Reference

# slice(stream) <>
# slice(buffer)
# slice(array)

Returns a sliceable source for the specified readable stream. The source may also be specified as an ArrayBuffer or a Uint8Array for reading from something that is already in-memory.

# source.read(length) <>

Returns a Promise for the next chunk of data from the underlying stream. The yielded result is an object with the following properties:

  • value - a Uint8Array, or undefined if the stream ended
  • done - a boolean which is true if the stream ended

The promise will be yielded with a value of length bytes, or the remaining bytes of the underlying stream if the underlying stream has more than zero but fewer than length bytes remaining. When no bytes remain in the stream, the yielded value will be undefined, and done will be true.

# source.cancel() <>

Returns a Promise which is resolved when the underlying stream has been destroyed.

Keywords

FAQs

Package last updated on 06 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc