readBlob.js 318 B

123456789101112131415
  1. const {asyncIterator} = Symbol;
  2. const readBlob = async function* (blob) {
  3. if (blob.stream) {
  4. yield* blob.stream()
  5. } else if (blob.arrayBuffer) {
  6. yield await blob.arrayBuffer()
  7. } else if (blob[asyncIterator]) {
  8. yield* blob[asyncIterator]();
  9. } else {
  10. yield blob;
  11. }
  12. }
  13. export default readBlob;