Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

miniprogram-blob

zyrong154MIT2.0.0TypeScript support: included

mini program blob polyfill

miniprogram, wx, winxin, 支付宝, 微信, 字节, 小程序, blob, polyfill

readme

miniprogram-blob

小程序的Blob polyfill。

此库参考Blob.js修改为小程序版本,并修复存在的问题


支持的小程序

  • 微信小程序
  • 支付宝小程序
  • 字节小程序

    其他小程序没有进行测试,可以自行测试


需要注意的问题

  • 需要注意的是小程序环境不支持ReadableStream,所以如果需要使用Blob.stream(),那么需要引入对应polyfill
  • Blob构造函数的第二个参数options.endings不支持指定为native

Example

import Blob from 'miniprogram-blob'

// 设置为全局对象
// globalThis.File = File

const blob = new Blob(['test'])
blob.arrayBuffer().then(buffer => {
  console.log(buffer)
})

TIP:
支付宝小程序IDE环境下globalThis为undefined,解决方法
字节小程序所有环境的globalThis都为undefined,暂时无法设置全局变量。


API

参考: https://developer.mozilla.org/zh-CN/docs/Web/API/Blob

changelog