When passed an (async)iterable that yields objects with a .byteLength property, throw if the cumulative value of that property reaches a limit.
.byteLength
import limitBytes from 'it-limit-bytes'import drain from 'it-drain'// This can also be an iterator, generator, etcconst values = [ Uint8Array.from([0, 1, 2, 3]), Uint8Array.from([4, 5, 6, 7])]drain(limitBytes(values, 5))// throws "Read too many bytes - 8/5" Copy
import limitBytes from 'it-limit-bytes'import drain from 'it-drain'// This can also be an iterator, generator, etcconst values = [ Uint8Array.from([0, 1, 2, 3]), Uint8Array.from([4, 5, 6, 7])]drain(limitBytes(values, 5))// throws "Read too many bytes - 8/5"
Async sources must be awaited:
import limitBytes from 'it-limit-bytes'import drain from 'it-drain'// This can also be an iterator, generator, etcconst values = [ Uint8Array.from([0, 1, 2, 3]), Uint8Array.from([4, 5, 6, 7])]await drain(limitBytes(values, 5))// throws "Read too many bytes - 8/5" Copy
import limitBytes from 'it-limit-bytes'import drain from 'it-drain'// This can also be an iterator, generator, etcconst values = [ Uint8Array.from([0, 1, 2, 3]), Uint8Array.from([4, 5, 6, 7])]await drain(limitBytes(values, 5))// throws "Read too many bytes - 8/5"
When passed an (async)iterable that yields objects with a
.byteLength
property, throw if the cumulative value of that property reaches a limit.Example
Async sources must be awaited: