7c84278473125dfcdb41b23440630daad73e25ef.svn-base 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /* Blob.js
  2. * A Blob, File, FileReader & URL implementation.
  3. * 2019-04-19
  4. *
  5. * By Eli Grey, http://eligrey.com
  6. * By Jimmy Wärting, https://github.com/jimmywarting
  7. * License: MIT
  8. * See https://github.com/eligrey/Blob.js/blob/master/LICENSE.md
  9. */
  10. ;(function () {
  11. var global =
  12. typeof window === "object" ? window : typeof self === "object" ? self : this
  13. var BlobBuilder =
  14. global.BlobBuilder ||
  15. global.WebKitBlobBuilder ||
  16. global.MSBlobBuilder ||
  17. global.MozBlobBuilder
  18. global.URL =
  19. global.URL ||
  20. global.webkitURL ||
  21. function (href, a) {
  22. a = document.createElement("a")
  23. a.href = href
  24. return a
  25. }
  26. var origBlob = global.Blob
  27. var createObjectURL = URL.createObjectURL
  28. var revokeObjectURL = URL.revokeObjectURL
  29. var strTag = global.Symbol && global.Symbol.toStringTag
  30. var blobSupported = false
  31. var blobSupportsArrayBufferView = false
  32. var arrayBufferSupported = !!global.ArrayBuffer
  33. var blobBuilderSupported =
  34. BlobBuilder && BlobBuilder.prototype.append && BlobBuilder.prototype.getBlob
  35. try {
  36. // Check if Blob constructor is supported
  37. blobSupported = new Blob(["ä"]).size === 2
  38. // Check if Blob constructor supports ArrayBufferViews
  39. // Fails in Safari 6, so we need to map to ArrayBuffers there.
  40. blobSupportsArrayBufferView = new Blob([new Uint8Array([1, 2])]).size === 2
  41. } catch (e) {}
  42. /**
  43. * Helper function that maps ArrayBufferViews to ArrayBuffers
  44. * Used by BlobBuilder constructor and old browsers that didn't
  45. * support it in the Blob constructor.
  46. */
  47. function mapArrayBufferViews (ary) {
  48. return ary.map(function (chunk) {
  49. if (chunk.buffer instanceof ArrayBuffer) {
  50. var buf = chunk.buffer
  51. // if this is a subarray, make a copy so we only
  52. // include the subarray region from the underlying buffer
  53. if (chunk.byteLength !== buf.byteLength) {
  54. var copy = new Uint8Array(chunk.byteLength)
  55. copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength))
  56. buf = copy.buffer
  57. }
  58. return buf
  59. }
  60. return chunk
  61. })
  62. }
  63. function BlobBuilderConstructor (ary, options) {
  64. options = options || {}
  65. var bb = new BlobBuilder()
  66. mapArrayBufferViews(ary).forEach(function (part) {
  67. bb.append(part)
  68. })
  69. return options.type ? bb.getBlob(options.type) : bb.getBlob()
  70. }
  71. function BlobConstructor (ary, options) {
  72. return new origBlob(mapArrayBufferViews(ary), options || {})
  73. }
  74. if (global.Blob) {
  75. BlobBuilderConstructor.prototype = Blob.prototype
  76. BlobConstructor.prototype = Blob.prototype
  77. }
  78. /********************************************************/
  79. /* String Encoder fallback */
  80. /********************************************************/
  81. function stringEncode (string) {
  82. var pos = 0
  83. var len = string.length
  84. var out = []
  85. var Arr = global.Uint8Array || Array // Use byte array when possible
  86. var at = 0 // output position
  87. var tlen = Math.max(32, len + (len >> 1) + 7) // 1.5x size
  88. var target = new Arr((tlen >> 3) << 3) // ... but at 8 byte offset
  89. while (pos < len) {
  90. var value = string.charCodeAt(pos++)
  91. if (value >= 0xd800 && value <= 0xdbff) {
  92. // high surrogate
  93. if (pos < len) {
  94. var extra = string.charCodeAt(pos)
  95. if ((extra & 0xfc00) === 0xdc00) {
  96. ++pos
  97. value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000
  98. }
  99. }
  100. if (value >= 0xd800 && value <= 0xdbff) {
  101. continue // drop lone surrogate
  102. }
  103. }
  104. // expand the buffer if we couldn't write 4 bytes
  105. if (at + 4 > target.length) {
  106. tlen += 8 // minimum extra
  107. tlen *= 1.0 + (pos / string.length) * 2 // take 2x the remaining
  108. tlen = (tlen >> 3) << 3 // 8 byte offset
  109. const update = new Uint8Array(tlen)
  110. update.set(target)
  111. target = update
  112. }
  113. if ((value & 0xffffff80) === 0) {
  114. // 1-byte
  115. target[at++] = value // ASCII
  116. continue
  117. } else if ((value & 0xfffff800) === 0) {
  118. // 2-byte
  119. target[at++] = ((value >> 6) & 0x1f) | 0xc0
  120. } else if ((value & 0xffff0000) === 0) {
  121. // 3-byte
  122. target[at++] = ((value >> 12) & 0x0f) | 0xe0
  123. target[at++] = ((value >> 6) & 0x3f) | 0x80
  124. } else if ((value & 0xffe00000) === 0) {
  125. // 4-byte
  126. target[at++] = ((value >> 18) & 0x07) | 0xf0
  127. target[at++] = ((value >> 12) & 0x3f) | 0x80
  128. target[at++] = ((value >> 6) & 0x3f) | 0x80
  129. } else {
  130. // FIXME: do we care
  131. continue
  132. }
  133. target[at++] = (value & 0x3f) | 0x80
  134. }
  135. return target.slice(0, at)
  136. }
  137. /********************************************************/
  138. /* String Decoder fallback */
  139. /********************************************************/
  140. function stringDecode (buf) {
  141. var end = buf.length
  142. var res = []
  143. var i = 0
  144. while (i < end) {
  145. var firstByte = buf[i]
  146. var codePoint = null
  147. var bytesPerSequence =
  148. firstByte > 0xef ? 4 : firstByte > 0xdf ? 3 : firstByte > 0xbf ? 2 : 1
  149. if (i + bytesPerSequence <= end) {
  150. var secondByte, thirdByte, fourthByte, tempCodePoint
  151. switch (bytesPerSequence) {
  152. case 1:
  153. if (firstByte < 0x80) {
  154. codePoint = firstByte
  155. }
  156. break
  157. case 2:
  158. secondByte = buf[i + 1]
  159. if ((secondByte & 0xc0) === 0x80) {
  160. tempCodePoint = ((firstByte & 0x1f) << 0x6) | (secondByte & 0x3f)
  161. if (tempCodePoint > 0x7f) {
  162. codePoint = tempCodePoint
  163. }
  164. }
  165. break
  166. case 3:
  167. secondByte = buf[i + 1]
  168. thirdByte = buf[i + 2]
  169. if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80) {
  170. tempCodePoint =
  171. ((firstByte & 0xf) << 0xc) |
  172. ((secondByte & 0x3f) << 0x6) |
  173. (thirdByte & 0x3f)
  174. if (
  175. tempCodePoint > 0x7ff &&
  176. (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff)
  177. ) {
  178. codePoint = tempCodePoint
  179. }
  180. }
  181. break
  182. case 4:
  183. secondByte = buf[i + 1]
  184. thirdByte = buf[i + 2]
  185. fourthByte = buf[i + 3]
  186. if (
  187. (secondByte & 0xc0) === 0x80 &&
  188. (thirdByte & 0xc0) === 0x80 &&
  189. (fourthByte & 0xc0) === 0x80
  190. ) {
  191. tempCodePoint =
  192. ((firstByte & 0xf) << 0x12) |
  193. ((secondByte & 0x3f) << 0xc) |
  194. ((thirdByte & 0x3f) << 0x6) |
  195. (fourthByte & 0x3f)
  196. if (tempCodePoint > 0xffff && tempCodePoint < 0x110000) {
  197. codePoint = tempCodePoint
  198. }
  199. }
  200. }
  201. }
  202. if (codePoint === null) {
  203. // we did not generate a valid codePoint so insert a
  204. // replacement char (U+FFFD) and advance only 1 byte
  205. codePoint = 0xfffd
  206. bytesPerSequence = 1
  207. } else if (codePoint > 0xffff) {
  208. // encode to utf16 (surrogate pair dance)
  209. codePoint -= 0x10000
  210. res.push(((codePoint >>> 10) & 0x3ff) | 0xd800)
  211. codePoint = 0xdc00 | (codePoint & 0x3ff)
  212. }
  213. res.push(codePoint)
  214. i += bytesPerSequence
  215. }
  216. var len = res.length
  217. var str = ""
  218. var i = 0
  219. while (i < len) {
  220. str += String.fromCharCode.apply(String, res.slice(i, (i += 0x1000)))
  221. }
  222. return str
  223. }
  224. // string -> buffer
  225. var textEncode =
  226. typeof TextEncoder === "function"
  227. ? TextEncoder.prototype.encode.bind(new TextEncoder())
  228. : stringEncode
  229. // buffer -> string
  230. var textDecode =
  231. typeof TextDecoder === "function"
  232. ? TextDecoder.prototype.decode.bind(new TextDecoder())
  233. : stringDecode
  234. function FakeBlobBuilder () {
  235. function isDataView (obj) {
  236. return obj && DataView.prototype.isPrototypeOf(obj)
  237. }
  238. function bufferClone (buf) {
  239. var view = new Array(buf.byteLength)
  240. var array = new Uint8Array(buf)
  241. var i = view.length
  242. while (i--) {
  243. view[i] = array[i]
  244. }
  245. return view
  246. }
  247. function array2base64 (input) {
  248. var byteToCharMap =
  249. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
  250. var output = []
  251. for (var i = 0; i < input.length; i += 3) {
  252. var byte1 = input[i]
  253. var haveByte2 = i + 1 < input.length
  254. var byte2 = haveByte2 ? input[i + 1] : 0
  255. var haveByte3 = i + 2 < input.length
  256. var byte3 = haveByte3 ? input[i + 2] : 0
  257. var outByte1 = byte1 >> 2
  258. var outByte2 = ((byte1 & 0x03) << 4) | (byte2 >> 4)
  259. var outByte3 = ((byte2 & 0x0f) << 2) | (byte3 >> 6)
  260. var outByte4 = byte3 & 0x3f
  261. if (!haveByte3) {
  262. outByte4 = 64
  263. if (!haveByte2) {
  264. outByte3 = 64
  265. }
  266. }
  267. output.push(
  268. byteToCharMap[outByte1],
  269. byteToCharMap[outByte2],
  270. byteToCharMap[outByte3],
  271. byteToCharMap[outByte4]
  272. )
  273. }
  274. return output.join("")
  275. }
  276. var create =
  277. Object.create ||
  278. function (a) {
  279. function c () {}
  280. c.prototype = a
  281. return new c()
  282. }
  283. if (arrayBufferSupported) {
  284. var viewClasses = [
  285. "[object Int8Array]",
  286. "[object Uint8Array]",
  287. "[object Uint8ClampedArray]",
  288. "[object Int16Array]",
  289. "[object Uint16Array]",
  290. "[object Int32Array]",
  291. "[object Uint32Array]",
  292. "[object Float32Array]",
  293. "[object Float64Array]"
  294. ]
  295. var isArrayBufferView =
  296. ArrayBuffer.isView ||
  297. function (obj) {
  298. return (
  299. obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
  300. )
  301. }
  302. }
  303. function concatTypedarrays (chunks) {
  304. var size = 0
  305. var i = chunks.length
  306. while (i--) {
  307. size += chunks[i].length
  308. }
  309. var b = new Uint8Array(size)
  310. var offset = 0
  311. for (i = 0, l = chunks.length; i < l; i++) {
  312. var chunk = chunks[i]
  313. b.set(chunk, offset)
  314. offset += chunk.byteLength || chunk.length
  315. }
  316. return b
  317. }
  318. /********************************************************/
  319. /* Blob constructor */
  320. /********************************************************/
  321. function Blob (chunks, opts) {
  322. chunks = chunks || []
  323. opts = opts == null ? {} : opts
  324. for (var i = 0, len = chunks.length; i < len; i++) {
  325. var chunk = chunks[i]
  326. if (chunk instanceof Blob) {
  327. chunks[i] = chunk._buffer
  328. } else if (typeof chunk === "string") {
  329. chunks[i] = textEncode(chunk)
  330. } else if (
  331. arrayBufferSupported &&
  332. (ArrayBuffer.prototype.isPrototypeOf(chunk) ||
  333. isArrayBufferView(chunk))
  334. ) {
  335. chunks[i] = bufferClone(chunk)
  336. } else if (arrayBufferSupported && isDataView(chunk)) {
  337. chunks[i] = bufferClone(chunk.buffer)
  338. } else {
  339. chunks[i] = textEncode(String(chunk))
  340. }
  341. }
  342. this._buffer = global.Uint8Array
  343. ? concatTypedarrays(chunks)
  344. : [].concat.apply([], chunks)
  345. this.size = this._buffer.length
  346. this.type = opts.type || ""
  347. if (/[^\u0020-\u007E]/.test(this.type)) {
  348. this.type = ""
  349. } else {
  350. this.type = this.type.toLowerCase()
  351. }
  352. }
  353. Blob.prototype.arrayBuffer = function () {
  354. return Promise.resolve(this._buffer)
  355. }
  356. Blob.prototype.text = function () {
  357. return Promise.resolve(textDecode(this._buffer))
  358. }
  359. Blob.prototype.slice = function (start, end, type) {
  360. var slice = this._buffer.slice(start || 0, end || this._buffer.length)
  361. return new Blob([slice], { type: type })
  362. }
  363. Blob.prototype.toString = function () {
  364. return "[object Blob]"
  365. }
  366. /********************************************************/
  367. /* File constructor */
  368. /********************************************************/
  369. function File (chunks, name, opts) {
  370. opts = opts || {}
  371. var a = Blob.call(this, chunks, opts) || this
  372. a.name = name.replace(/\//g, ":")
  373. a.lastModifiedDate = opts.lastModified
  374. ? new Date(opts.lastModified)
  375. : new Date()
  376. a.lastModified = +a.lastModifiedDate
  377. return a
  378. }
  379. File.prototype = create(Blob.prototype)
  380. File.prototype.constructor = File
  381. if (Object.setPrototypeOf) {
  382. Object.setPrototypeOf(File, Blob)
  383. } else {
  384. try {
  385. File.__proto__ = Blob
  386. } catch (e) {}
  387. }
  388. File.prototype.toString = function () {
  389. return "[object File]"
  390. }
  391. /********************************************************/
  392. /* FileReader constructor */
  393. /********************************************************/
  394. function FileReader () {
  395. if (!(this instanceof FileReader)) {
  396. throw new TypeError(
  397. "Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function."
  398. )
  399. }
  400. var delegate = document.createDocumentFragment()
  401. this.addEventListener = delegate.addEventListener
  402. this.dispatchEvent = function (evt) {
  403. var local = this["on" + evt.type]
  404. if (typeof local === "function") local(evt)
  405. delegate.dispatchEvent(evt)
  406. }
  407. this.removeEventListener = delegate.removeEventListener
  408. }
  409. function _read (fr, blob, kind) {
  410. if (!(blob instanceof Blob)) {
  411. throw new TypeError(
  412. "Failed to execute '" +
  413. kind +
  414. "' on 'FileReader': parameter 1 is not of type 'Blob'."
  415. )
  416. }
  417. fr.result = ""
  418. setTimeout(function () {
  419. this.readyState = FileReader.LOADING
  420. fr.dispatchEvent(new Event("load"))
  421. fr.dispatchEvent(new Event("loadend"))
  422. })
  423. }
  424. FileReader.EMPTY = 0
  425. FileReader.LOADING = 1
  426. FileReader.DONE = 2
  427. FileReader.prototype.error = null
  428. FileReader.prototype.onabort = null
  429. FileReader.prototype.onerror = null
  430. FileReader.prototype.onload = null
  431. FileReader.prototype.onloadend = null
  432. FileReader.prototype.onloadstart = null
  433. FileReader.prototype.onprogress = null
  434. FileReader.prototype.readAsDataURL = function (blob) {
  435. _read(this, blob, "readAsDataURL")
  436. this.result =
  437. "data:" + blob.type + ";base64," + array2base64(blob._buffer)
  438. }
  439. FileReader.prototype.readAsText = function (blob) {
  440. _read(this, blob, "readAsText")
  441. this.result = textDecode(blob._buffer)
  442. }
  443. FileReader.prototype.readAsArrayBuffer = function (blob) {
  444. _read(this, blob, "readAsText")
  445. // return ArrayBuffer when possible
  446. this.result = (blob._buffer.buffer || blob._buffer).slice()
  447. }
  448. FileReader.prototype.abort = function () {}
  449. /********************************************************/
  450. /* URL */
  451. /********************************************************/
  452. URL.createObjectURL = function (blob) {
  453. return blob instanceof Blob
  454. ? "data:" + blob.type + ";base64," + array2base64(blob._buffer)
  455. : createObjectURL.call(URL, blob)
  456. }
  457. URL.revokeObjectURL = function (url) {
  458. revokeObjectURL && revokeObjectURL.call(URL, url)
  459. }
  460. /********************************************************/
  461. /* XHR */
  462. /********************************************************/
  463. var _send = global.XMLHttpRequest && global.XMLHttpRequest.prototype.send
  464. if (_send) {
  465. XMLHttpRequest.prototype.send = function (data) {
  466. if (data instanceof Blob) {
  467. this.setRequestHeader("Content-Type", data.type)
  468. _send.call(this, textDecode(data._buffer))
  469. } else {
  470. _send.call(this, data)
  471. }
  472. }
  473. }
  474. global.FileReader = FileReader
  475. global.File = File
  476. global.Blob = Blob
  477. }
  478. function fixFileAndXHR () {
  479. var isIE =
  480. !!global.ActiveXObject ||
  481. ("-ms-scroll-limit" in document.documentElement.style &&
  482. "-ms-ime-align" in document.documentElement.style)
  483. // Monkey patched
  484. // IE don't set Content-Type header on XHR whose body is a typed Blob
  485. // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6047383
  486. var _send = global.XMLHttpRequest && global.XMLHttpRequest.prototype.send
  487. if (isIE && _send) {
  488. XMLHttpRequest.prototype.send = function (data) {
  489. if (data instanceof Blob) {
  490. this.setRequestHeader("Content-Type", data.type)
  491. _send.call(this, data)
  492. } else {
  493. _send.call(this, data)
  494. }
  495. }
  496. }
  497. try {
  498. new File([], "")
  499. } catch (e) {
  500. try {
  501. var klass = new Function(
  502. "class File extends Blob {" +
  503. "constructor(chunks, name, opts) {" +
  504. "opts = opts || {};" +
  505. "super(chunks, opts || {});" +
  506. "this.name = name.replace(///g, \":\");" +
  507. "this.lastModifiedDate = opts.lastModified ? new Date(opts.lastModified) : new Date();" +
  508. "this.lastModified = +this.lastModifiedDate;" +
  509. "}};" +
  510. "return new File([], \"\"), File"
  511. )()
  512. global.File = klass
  513. } catch (e) {
  514. var klass = function (b, d, c) {
  515. var blob = new Blob(b, c)
  516. var t =
  517. c && void 0 !== c.lastModified
  518. ? new Date(c.lastModified)
  519. : new Date()
  520. blob.name = d.replace(/\//g, ":")
  521. blob.lastModifiedDate = t
  522. blob.lastModified = +t
  523. blob.toString = function () {
  524. return "[object File]"
  525. }
  526. if (strTag) {
  527. blob[strTag] = "File"
  528. }
  529. return blob
  530. }
  531. global.File = klass
  532. }
  533. }
  534. }
  535. if (blobSupported) {
  536. fixFileAndXHR()
  537. global.Blob = blobSupportsArrayBufferView ? global.Blob : BlobConstructor
  538. } else if (blobBuilderSupported) {
  539. fixFileAndXHR()
  540. global.Blob = BlobBuilderConstructor
  541. } else {
  542. FakeBlobBuilder()
  543. }
  544. if (strTag) {
  545. File.prototype[strTag] = "File"
  546. Blob.prototype[strTag] = "Blob"
  547. FileReader.prototype[strTag] = "FileReader"
  548. }
  549. var blob = global.Blob.prototype
  550. var stream
  551. function promisify (obj) {
  552. return new Promise(function (resolve, reject) {
  553. obj.onload = obj.onerror = function (evt) {
  554. obj.onload = obj.onerror = null
  555. evt.type === "load"
  556. ? resolve(obj.result || obj)
  557. : reject(new Error("Failed to read the blob/file"))
  558. }
  559. })
  560. }
  561. try {
  562. new ReadableStream({ type: "bytes" })
  563. stream = function stream () {
  564. var position = 0
  565. var blob = this
  566. return new ReadableStream({
  567. type: "bytes",
  568. autoAllocateChunkSize: 524288,
  569. pull: function (controller) {
  570. var v = controller.byobRequest.view
  571. var chunk = blob.slice(position, position + v.byteLength)
  572. return chunk.arrayBuffer().then(function (buffer) {
  573. var uint8array = new Uint8Array(buffer)
  574. var bytesRead = uint8array.byteLength
  575. position += bytesRead
  576. v.set(uint8array)
  577. controller.byobRequest.respond(bytesRead)
  578. if (position >= blob.size) controller.close()
  579. })
  580. }
  581. })
  582. }
  583. } catch (e) {
  584. try {
  585. new ReadableStream({})
  586. stream = function stream (blob) {
  587. var position = 0
  588. var blob = this
  589. return new ReadableStream({
  590. pull: function (controller) {
  591. var chunk = blob.slice(position, position + 524288)
  592. return chunk.arrayBuffer().then(function (buffer) {
  593. position += buffer.byteLength
  594. var uint8array = new Uint8Array(buffer)
  595. controller.enqueue(uint8array)
  596. if (position == blob.size) controller.close()
  597. })
  598. }
  599. })
  600. }
  601. } catch (e) {
  602. try {
  603. new Response("").body.getReader().read()
  604. stream = function stream () {
  605. return new Response(this).body
  606. }
  607. } catch (e) {
  608. stream = function stream () {
  609. throw new Error(
  610. "Include https://github.com/MattiasBuelens/web-streams-polyfill"
  611. )
  612. }
  613. }
  614. }
  615. }
  616. if (!blob.arrayBuffer) {
  617. blob.arrayBuffer = function arrayBuffer () {
  618. var fr = new FileReader()
  619. fr.readAsArrayBuffer(this)
  620. return promisify(fr)
  621. }
  622. }
  623. if (!blob.text) {
  624. blob.text = function text () {
  625. var fr = new FileReader()
  626. fr.readAsText(this)
  627. return promisify(fr)
  628. }
  629. }
  630. if (!blob.stream) {
  631. blob.stream = stream
  632. }
  633. })()