UNPKG

slice-source

Version:

A readable stream reader that reads a desired number of bytes.

15 lines (13 loc) 442 B
import concat from "./concat"; import empty from "./empty"; export default function() { var that = this, array = that._array.subarray(that._index); return that._source.read().then(function(result) { that._array = empty; that._index = 0; return result.done ? (array.length > 0 ? {done: false, value: array} : {done: true, value: undefined}) : {done: false, value: concat(array, result.value)}; }); }