blob2web-stream
Read W3C Blob & File objects as a Web stream.
Getting started
Load it however you want
require('blob2web-stream')
import from 'blob2web-stream'
<script src="https://wzrd.in/standalone/blob2web-stream@1.0.0"></script>
<script src="https://cdn.rawgit.com/jimmywarting/blob2web-stream/master/blob2web-stream"></script>
EXAMPLE
<script src="https://wzrd.in/standalone/blob2web-stream@1.0.0"></script>
<script src="https://wzrd.in/standalone/web-streams-polyfill@1.1.1"
integrity="sha384-8EYry4yokV53rGHMFtPqeVlAPgxn8yxr/RvxC4bZt3vlneaDPzWkSJCvBDBTuXAV"
crossorigin
></script>
<script>
var myFile = new File(['parts'], 'filename.txt')
var stream = myFile._createReadableByteStream()
// You can do this
stream.pipeTo(destination)
// or this
stream
.pipeThrough(decompressorTransform)
.pipeThrough(ignoreNonImageFilesTransform)
.pipeTo(mediaGallery);
// Or more manual work...
// Web streams need a consumer to read the data unlike node-streams where
// you get data from a data-event. Web streams it's also all promisifed.
var reader = readableStream.getReader()
var chunks = []
var pump() =>
reader.read().then( ({ value, done }) => {
if (done)
return chunks
chunks.push(value) // Uint8array
return pump()
})
pump().then(chunks => {
console.log('done reading the hole file')
console.log(chunks)
})
</script>