buffer.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. "use strict";
  2. (function()
  3. {
  4. v86util.SyncBuffer = SyncBuffer;
  5. v86util.AsyncXHRBuffer = AsyncXHRBuffer;
  6. v86util.AsyncXHRPartfileBuffer = AsyncXHRPartfileBuffer;
  7. v86util.AsyncFileBuffer = AsyncFileBuffer;
  8. v86util.SyncFileBuffer = SyncFileBuffer;
  9. // The smallest size the emulated hardware can emit
  10. const BLOCK_SIZE = 256;
  11. const ASYNC_SAFE = false;
  12. /**
  13. * Synchronous access to ArrayBuffer
  14. * @constructor
  15. */
  16. function SyncBuffer(buffer)
  17. {
  18. dbg_assert(buffer instanceof ArrayBuffer);
  19. this.buffer = buffer;
  20. this.byteLength = buffer.byteLength;
  21. this.onload = undefined;
  22. this.onprogress = undefined;
  23. }
  24. SyncBuffer.prototype.load = function()
  25. {
  26. this.onload && this.onload({ buffer: this.buffer });
  27. };
  28. /**
  29. * @this {SyncBuffer|SyncFileBuffer}
  30. * @param {number} start
  31. * @param {number} len
  32. * @param {function(!Uint8Array)} fn
  33. */
  34. SyncBuffer.prototype.get = function(start, len, fn)
  35. {
  36. dbg_assert(start + len <= this.byteLength);
  37. fn(new Uint8Array(this.buffer, start, len));
  38. };
  39. /**
  40. * @this {SyncBuffer|SyncFileBuffer}
  41. * @param {number} start
  42. * @param {!Uint8Array} slice
  43. * @param {function()} fn
  44. */
  45. SyncBuffer.prototype.set = function(start, slice, fn)
  46. {
  47. dbg_assert(start + slice.byteLength <= this.byteLength);
  48. new Uint8Array(this.buffer, start, slice.byteLength).set(slice);
  49. fn();
  50. };
  51. /**
  52. * @this {SyncBuffer|SyncFileBuffer}
  53. * @param {function(!ArrayBuffer)} fn
  54. */
  55. SyncBuffer.prototype.get_buffer = function(fn)
  56. {
  57. fn(this.buffer);
  58. };
  59. /**
  60. * @this {SyncBuffer|SyncFileBuffer}
  61. */
  62. SyncBuffer.prototype.get_state = function()
  63. {
  64. const state = [];
  65. state[0] = this.byteLength;
  66. state[1] = new Uint8Array(this.buffer);
  67. return state;
  68. };
  69. /**
  70. * @this {SyncBuffer|SyncFileBuffer}
  71. */
  72. SyncBuffer.prototype.set_state = function(state)
  73. {
  74. this.byteLength = state[0];
  75. this.buffer = state[1].slice().buffer;
  76. };
  77. /**
  78. * Asynchronous access to ArrayBuffer, loading blocks lazily as needed,
  79. * using the `Range: bytes=...` header
  80. *
  81. * @constructor
  82. * @param {string} filename Name of the file to download
  83. * @param {number|undefined} size
  84. * @param {number|undefined} fixed_chunk_size
  85. */
  86. function AsyncXHRBuffer(filename, size, fixed_chunk_size)
  87. {
  88. this.filename = filename;
  89. this.byteLength = size;
  90. this.block_cache = new Map();
  91. this.block_cache_is_write = new Set();
  92. this.fixed_chunk_size = fixed_chunk_size;
  93. this.cache_reads = !!fixed_chunk_size; // TODO: could also be useful in other cases (needs testing)
  94. this.onload = undefined;
  95. this.onprogress = undefined;
  96. }
  97. AsyncXHRBuffer.prototype.load = function()
  98. {
  99. if(this.byteLength !== undefined)
  100. {
  101. this.onload && this.onload(Object.create(null));
  102. return;
  103. }
  104. // Determine the size using a request
  105. determine_size(this.filename, (error, size) =>
  106. {
  107. if(error)
  108. {
  109. throw new Error("Cannot use: " + this.filename + ". " + error);
  110. }
  111. else
  112. {
  113. dbg_assert(size >= 0);
  114. this.byteLength = size;
  115. this.onload && this.onload(Object.create(null));
  116. }
  117. });
  118. };
  119. /**
  120. * @param {number} offset
  121. * @param {number} len
  122. * @this {AsyncXHRBuffer|AsyncXHRPartfileBuffer|AsyncFileBuffer}
  123. */
  124. AsyncXHRBuffer.prototype.get_from_cache = function(offset, len)
  125. {
  126. var number_of_blocks = len / BLOCK_SIZE;
  127. var block_index = offset / BLOCK_SIZE;
  128. for(var i = 0; i < number_of_blocks; i++)
  129. {
  130. var block = this.block_cache.get(block_index + i);
  131. if(!block)
  132. {
  133. return;
  134. }
  135. }
  136. if(number_of_blocks === 1)
  137. {
  138. return this.block_cache.get(block_index);
  139. }
  140. else
  141. {
  142. var result = new Uint8Array(len);
  143. for(var i = 0; i < number_of_blocks; i++)
  144. {
  145. result.set(this.block_cache.get(block_index + i), i * BLOCK_SIZE);
  146. }
  147. return result;
  148. }
  149. };
  150. /**
  151. * @param {number} offset
  152. * @param {number} len
  153. * @param {function(!Uint8Array)} fn
  154. */
  155. AsyncXHRBuffer.prototype.get = function(offset, len, fn)
  156. {
  157. dbg_assert(offset + len <= this.byteLength);
  158. dbg_assert(offset % BLOCK_SIZE === 0);
  159. dbg_assert(len % BLOCK_SIZE === 0);
  160. dbg_assert(len);
  161. var block = this.get_from_cache(offset, len);
  162. if(block)
  163. {
  164. if(ASYNC_SAFE)
  165. {
  166. setTimeout(fn.bind(this, block), 0);
  167. }
  168. else
  169. {
  170. fn(block);
  171. }
  172. return;
  173. }
  174. var requested_start = offset;
  175. var requested_length = len;
  176. if(this.fixed_chunk_size)
  177. {
  178. requested_start = offset - (offset % this.fixed_chunk_size);
  179. requested_length = Math.ceil((offset - requested_start + len) / this.fixed_chunk_size) * this.fixed_chunk_size;
  180. }
  181. v86util.load_file(this.filename, {
  182. done: function done(buffer)
  183. {
  184. var block = new Uint8Array(buffer);
  185. this.handle_read(requested_start, requested_length, block);
  186. if(requested_start === offset && requested_length === len)
  187. {
  188. fn(block);
  189. }
  190. else
  191. {
  192. fn(block.subarray(offset - requested_start, offset - requested_start + len));
  193. }
  194. }.bind(this),
  195. range: { start: requested_start, length: requested_length },
  196. });
  197. };
  198. /**
  199. * Relies on this.byteLength and this.block_cache
  200. *
  201. * @this {AsyncXHRBuffer|AsyncXHRPartfileBuffer|AsyncFileBuffer}
  202. *
  203. * @param {number} start
  204. * @param {!Uint8Array} data
  205. * @param {function()} fn
  206. */
  207. AsyncXHRBuffer.prototype.set = function(start, data, fn)
  208. {
  209. var len = data.length;
  210. dbg_assert(start + data.byteLength <= this.byteLength);
  211. dbg_assert(start % BLOCK_SIZE === 0);
  212. dbg_assert(len % BLOCK_SIZE === 0);
  213. dbg_assert(len);
  214. var start_block = start / BLOCK_SIZE;
  215. var block_count = len / BLOCK_SIZE;
  216. for(var i = 0; i < block_count; i++)
  217. {
  218. var block = this.block_cache.get(start_block + i);
  219. if(block === undefined)
  220. {
  221. const data_slice = data.slice(i * BLOCK_SIZE, (i + 1) * BLOCK_SIZE);
  222. this.block_cache.set(start_block + i, data_slice);
  223. }
  224. else
  225. {
  226. const data_slice = data.subarray(i * BLOCK_SIZE, (i + 1) * BLOCK_SIZE);
  227. dbg_assert(block.byteLength === data_slice.length);
  228. block.set(data_slice);
  229. }
  230. this.block_cache_is_write.add(start_block + i);
  231. }
  232. fn();
  233. };
  234. /**
  235. * @this {AsyncXHRBuffer|AsyncXHRPartfileBuffer|AsyncFileBuffer}
  236. * @param {number} offset
  237. * @param {number} len
  238. * @param {!Uint8Array} block
  239. */
  240. AsyncXHRBuffer.prototype.handle_read = function(offset, len, block)
  241. {
  242. // Used by AsyncXHRBuffer, AsyncXHRPartfileBuffer and AsyncFileBuffer
  243. // Overwrites blocks from the original source that have been written since
  244. var start_block = offset / BLOCK_SIZE;
  245. var block_count = len / BLOCK_SIZE;
  246. for(var i = 0; i < block_count; i++)
  247. {
  248. const cached_block = this.block_cache.get(start_block + i);
  249. if(cached_block)
  250. {
  251. block.set(cached_block, i * BLOCK_SIZE);
  252. }
  253. else if(this.cache_reads)
  254. {
  255. this.block_cache.set(start_block + i, block.slice(i * BLOCK_SIZE, (i + 1) * BLOCK_SIZE));
  256. }
  257. }
  258. };
  259. AsyncXHRBuffer.prototype.get_buffer = function(fn)
  260. {
  261. // We must download all parts, unlikely a good idea for big files
  262. fn();
  263. };
  264. ///**
  265. // * @this {AsyncXHRBuffer|AsyncXHRPartfileBuffer|AsyncFileBuffer}
  266. // */
  267. //AsyncXHRBuffer.prototype.get_block_cache = function()
  268. //{
  269. // var count = Object.keys(this.block_cache).length;
  270. // var buffer = new Uint8Array(count * BLOCK_SIZE);
  271. // var indices = [];
  272. // var i = 0;
  273. // for(var index of Object.keys(this.block_cache))
  274. // {
  275. // var block = this.block_cache.get(index);
  276. // dbg_assert(block.length === BLOCK_SIZE);
  277. // index = +index;
  278. // indices.push(index);
  279. // buffer.set(
  280. // block,
  281. // i * BLOCK_SIZE
  282. // );
  283. // i++;
  284. // }
  285. // return {
  286. // buffer,
  287. // indices,
  288. // block_size: BLOCK_SIZE,
  289. // };
  290. //};
  291. /**
  292. * @this {AsyncXHRBuffer|AsyncXHRPartfileBuffer|AsyncFileBuffer}
  293. */
  294. AsyncXHRBuffer.prototype.get_state = function()
  295. {
  296. const state = [];
  297. const block_cache = [];
  298. for(let [index, block] of this.block_cache)
  299. {
  300. dbg_assert(isFinite(index));
  301. if(this.block_cache_is_write.has(index))
  302. {
  303. block_cache.push([index, block]);
  304. }
  305. }
  306. state[0] = block_cache;
  307. return state;
  308. };
  309. /**
  310. * @this {AsyncXHRBuffer|AsyncXHRPartfileBuffer|AsyncFileBuffer}
  311. */
  312. AsyncXHRBuffer.prototype.set_state = function(state)
  313. {
  314. const block_cache = state[0];
  315. this.block_cache.clear();
  316. this.block_cache_is_write.clear();
  317. for(let [index, block] of block_cache)
  318. {
  319. dbg_assert(isFinite(index));
  320. this.block_cache.set(index, block);
  321. this.block_cache_is_write.add(index);
  322. }
  323. };
  324. /**
  325. * Asynchronous access to ArrayBuffer, loading blocks lazily as needed,
  326. * downloading files named filename-%d-%d.ext (where the %d are start and end offset).
  327. * Or, if partfile_alt_format is set, filename-%08d.ext (where %d is the part number, compatible with gnu split).
  328. *
  329. * @constructor
  330. * @param {string} filename Name of the file to download
  331. * @param {number|undefined} size
  332. * @param {number|undefined} fixed_chunk_size
  333. * @param {boolean|undefined} partfile_alt_format
  334. */
  335. function AsyncXHRPartfileBuffer(filename, size, fixed_chunk_size, partfile_alt_format)
  336. {
  337. const parts = filename.match(/(.*)(\..*)/);
  338. if(parts)
  339. {
  340. this.basename = parts[1];
  341. this.extension = parts[2];
  342. }
  343. else
  344. {
  345. this.basename = filename;
  346. this.extension = "";
  347. }
  348. if(!this.basename.endsWith("/"))
  349. {
  350. this.basename += "-";
  351. }
  352. this.block_cache = new Map();
  353. this.block_cache_is_write = new Set();
  354. this.byteLength = size;
  355. this.fixed_chunk_size = fixed_chunk_size;
  356. this.partfile_alt_format = !!partfile_alt_format;
  357. this.cache_reads = !!fixed_chunk_size; // TODO: could also be useful in other cases (needs testing)
  358. this.onload = undefined;
  359. this.onprogress = undefined;
  360. }
  361. AsyncXHRPartfileBuffer.prototype.load = function()
  362. {
  363. if(this.byteLength !== undefined)
  364. {
  365. this.onload && this.onload(Object.create(null));
  366. return;
  367. }
  368. dbg_assert(false);
  369. this.onload && this.onload(Object.create(null));
  370. };
  371. /**
  372. * @param {number} offset
  373. * @param {number} len
  374. * @param {function(!Uint8Array)} fn
  375. */
  376. AsyncXHRPartfileBuffer.prototype.get = function(offset, len, fn)
  377. {
  378. dbg_assert(offset + len <= this.byteLength);
  379. dbg_assert(offset % BLOCK_SIZE === 0);
  380. dbg_assert(len % BLOCK_SIZE === 0);
  381. dbg_assert(len);
  382. const block = this.get_from_cache(offset, len);
  383. if(block)
  384. {
  385. if(ASYNC_SAFE)
  386. {
  387. setTimeout(fn.bind(this, block), 0);
  388. }
  389. else
  390. {
  391. fn(block);
  392. }
  393. return;
  394. }
  395. if(this.fixed_chunk_size)
  396. {
  397. const start_index = Math.floor(offset / this.fixed_chunk_size);
  398. const m_offset = offset - start_index * this.fixed_chunk_size;
  399. dbg_assert(m_offset >= 0);
  400. const total_count = Math.ceil((m_offset + len) / this.fixed_chunk_size);
  401. const blocks = new Uint8Array(total_count * this.fixed_chunk_size);
  402. let finished = 0;
  403. for(let i = 0; i < total_count; i++)
  404. {
  405. const offset = (start_index + i) * this.fixed_chunk_size;
  406. const part_filename =
  407. this.partfile_alt_format ?
  408. // matches output of gnu split:
  409. // split -b 512 -a8 -d --additional-suffix .img w95.img w95-
  410. this.basename + (start_index + i + "").padStart(8, "0") + this.extension
  411. :
  412. this.basename + offset + "-" + (offset + this.fixed_chunk_size) + this.extension;
  413. // XXX: unnecessary allocation
  414. const block = this.get_from_cache(offset, this.fixed_chunk_size);
  415. if(block)
  416. {
  417. const cur = i * this.fixed_chunk_size;
  418. blocks.set(block, cur);
  419. finished++;
  420. if(finished === total_count)
  421. {
  422. const tmp_blocks = blocks.subarray(m_offset, m_offset + len);
  423. fn(tmp_blocks);
  424. }
  425. }
  426. else
  427. {
  428. v86util.load_file(part_filename, {
  429. done: function done(buffer)
  430. {
  431. const cur = i * this.fixed_chunk_size;
  432. const block = new Uint8Array(buffer);
  433. this.handle_read((start_index + i) * this.fixed_chunk_size, this.fixed_chunk_size|0, block);
  434. blocks.set(block, cur);
  435. finished++;
  436. if(finished === total_count)
  437. {
  438. const tmp_blocks = blocks.subarray(m_offset, m_offset + len);
  439. fn(tmp_blocks);
  440. }
  441. }.bind(this),
  442. });
  443. }
  444. }
  445. }
  446. else
  447. {
  448. const part_filename = this.basename + offset + "-" + (offset + len) + this.extension;
  449. v86util.load_file(part_filename, {
  450. done: function done(buffer)
  451. {
  452. dbg_assert(buffer.byteLength === len);
  453. var block = new Uint8Array(buffer);
  454. this.handle_read(offset, len, block);
  455. fn(block);
  456. }.bind(this),
  457. });
  458. }
  459. };
  460. AsyncXHRPartfileBuffer.prototype.get_from_cache = AsyncXHRBuffer.prototype.get_from_cache;
  461. AsyncXHRPartfileBuffer.prototype.set = AsyncXHRBuffer.prototype.set;
  462. AsyncXHRPartfileBuffer.prototype.handle_read = AsyncXHRBuffer.prototype.handle_read;
  463. //AsyncXHRPartfileBuffer.prototype.get_block_cache = AsyncXHRBuffer.prototype.get_block_cache;
  464. AsyncXHRPartfileBuffer.prototype.get_state = AsyncXHRBuffer.prototype.get_state;
  465. AsyncXHRPartfileBuffer.prototype.set_state = AsyncXHRBuffer.prototype.set_state;
  466. /**
  467. * Synchronous access to File, loading blocks from the input type=file
  468. * The whole file is loaded into memory during initialisation
  469. *
  470. * @constructor
  471. */
  472. function SyncFileBuffer(file)
  473. {
  474. this.file = file;
  475. this.byteLength = file.size;
  476. if(file.size > (1 << 30))
  477. {
  478. console.warn("SyncFileBuffer: Allocating buffer of " + (file.size >> 20) + " MB ...");
  479. }
  480. this.buffer = new ArrayBuffer(file.size);
  481. this.onload = undefined;
  482. this.onprogress = undefined;
  483. }
  484. SyncFileBuffer.prototype.load = function()
  485. {
  486. this.load_next(0);
  487. };
  488. /**
  489. * @param {number} start
  490. */
  491. SyncFileBuffer.prototype.load_next = function(start)
  492. {
  493. /** @const */
  494. var PART_SIZE = 4 << 20;
  495. var filereader = new FileReader();
  496. filereader.onload = function(e)
  497. {
  498. var buffer = new Uint8Array(e.target.result);
  499. new Uint8Array(this.buffer, start).set(buffer);
  500. this.load_next(start + PART_SIZE);
  501. }.bind(this);
  502. if(this.onprogress)
  503. {
  504. this.onprogress({
  505. loaded: start,
  506. total: this.byteLength,
  507. lengthComputable: true,
  508. });
  509. }
  510. if(start < this.byteLength)
  511. {
  512. var end = Math.min(start + PART_SIZE, this.byteLength);
  513. var slice = this.file.slice(start, end);
  514. filereader.readAsArrayBuffer(slice);
  515. }
  516. else
  517. {
  518. this.file = undefined;
  519. this.onload && this.onload({ buffer: this.buffer });
  520. }
  521. };
  522. SyncFileBuffer.prototype.get = SyncBuffer.prototype.get;
  523. SyncFileBuffer.prototype.set = SyncBuffer.prototype.set;
  524. SyncFileBuffer.prototype.get_buffer = SyncBuffer.prototype.get_buffer;
  525. SyncFileBuffer.prototype.get_state = SyncBuffer.prototype.get_state;
  526. SyncFileBuffer.prototype.set_state = SyncBuffer.prototype.set_state;
  527. /**
  528. * Asynchronous access to File, loading blocks from the input type=file
  529. *
  530. * @constructor
  531. */
  532. function AsyncFileBuffer(file)
  533. {
  534. this.file = file;
  535. this.byteLength = file.size;
  536. this.block_cache = new Map();
  537. this.block_cache_is_write = new Set();
  538. this.onload = undefined;
  539. this.onprogress = undefined;
  540. }
  541. AsyncFileBuffer.prototype.load = function()
  542. {
  543. this.onload && this.onload(Object.create(null));
  544. };
  545. /**
  546. * @param {number} offset
  547. * @param {number} len
  548. * @param {function(!Uint8Array)} fn
  549. */
  550. AsyncFileBuffer.prototype.get = function(offset, len, fn)
  551. {
  552. dbg_assert(offset % BLOCK_SIZE === 0);
  553. dbg_assert(len % BLOCK_SIZE === 0);
  554. dbg_assert(len);
  555. var block = this.get_from_cache(offset, len);
  556. if(block)
  557. {
  558. fn(block);
  559. return;
  560. }
  561. var fr = new FileReader();
  562. fr.onload = function(e)
  563. {
  564. var buffer = e.target.result;
  565. var block = new Uint8Array(buffer);
  566. this.handle_read(offset, len, block);
  567. fn(block);
  568. }.bind(this);
  569. fr.readAsArrayBuffer(this.file.slice(offset, offset + len));
  570. };
  571. AsyncFileBuffer.prototype.get_from_cache = AsyncXHRBuffer.prototype.get_from_cache;
  572. AsyncFileBuffer.prototype.set = AsyncXHRBuffer.prototype.set;
  573. AsyncFileBuffer.prototype.handle_read = AsyncXHRBuffer.prototype.handle_read;
  574. AsyncFileBuffer.prototype.get_state = AsyncXHRBuffer.prototype.get_state;
  575. AsyncFileBuffer.prototype.set_state = AsyncXHRBuffer.prototype.set_state;
  576. AsyncFileBuffer.prototype.get_buffer = function(fn)
  577. {
  578. // We must load all parts, unlikely a good idea for big files
  579. fn();
  580. };
  581. AsyncFileBuffer.prototype.get_as_file = function(name)
  582. {
  583. var parts = [];
  584. var existing_blocks = Array.from(this.block_cache.keys()).sort(function(x, y) { return x - y; });
  585. var current_offset = 0;
  586. for(var i = 0; i < existing_blocks.length; i++)
  587. {
  588. var block_index = existing_blocks[i];
  589. var block = this.block_cache.get(block_index);
  590. var start = block_index * BLOCK_SIZE;
  591. dbg_assert(start >= current_offset);
  592. if(start !== current_offset)
  593. {
  594. parts.push(this.file.slice(current_offset, start));
  595. current_offset = start;
  596. }
  597. parts.push(block);
  598. current_offset += block.length;
  599. }
  600. if(current_offset !== this.file.size)
  601. {
  602. parts.push(this.file.slice(current_offset));
  603. }
  604. var file = new File(parts, name);
  605. dbg_assert(file.size === this.file.size);
  606. return file;
  607. };
  608. if(typeof XMLHttpRequest === "undefined")
  609. {
  610. var determine_size = function(path, cb)
  611. {
  612. require("fs")["stat"](path, (err, stats) =>
  613. {
  614. if(err)
  615. {
  616. cb(err);
  617. }
  618. else
  619. {
  620. cb(null, stats.size);
  621. }
  622. });
  623. };
  624. }
  625. else
  626. {
  627. var determine_size = function(url, cb)
  628. {
  629. v86util.load_file(url, {
  630. done: (buffer, http) =>
  631. {
  632. var header = http.getResponseHeader("Content-Range") || "";
  633. var match = header.match(/\/(\d+)\s*$/);
  634. if(match)
  635. {
  636. cb(null, +match[1]);
  637. }
  638. else
  639. {
  640. const error = "`Range: bytes=...` header not supported (Got `" + header + "`)";
  641. cb(error);
  642. }
  643. },
  644. headers: {
  645. Range: "bytes=0-0",
  646. }
  647. });
  648. };
  649. }
  650. })();