1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.parseVhdToBlocks = parseVhdToBlocks;
|
7 | var _assert = _interopRequireDefault(require("assert"));
|
8 | var _parseVhdStream = require("vhd-lib/parseVhdStream.js");
|
9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10 | async function next(iterator, type, skipableType) {
|
11 | let item;
|
12 | do {
|
13 | const cursor = await iterator.next();
|
14 | _assert.default.strictEqual(cursor.done, false, 'iterator is done');
|
15 | item = cursor.value;
|
16 | } while (item.type === skipableType);
|
17 | _assert.default.strictEqual(item.type, type);
|
18 | return item;
|
19 | }
|
20 | async function* onlyBlocks(iterable, blockSize) {
|
21 | for await (const item of iterable) {
|
22 | if (item.type === 'block') {
|
23 | const {
|
24 | id,
|
25 | data
|
26 | } = item;
|
27 | yield {
|
28 | lba: id * blockSize,
|
29 | block: data
|
30 | };
|
31 | }
|
32 | }
|
33 | }
|
34 | async function parseVhdToBlocks(vhdStream) {
|
35 | const iterator = (0, _parseVhdStream.parseVhdStream)(vhdStream);
|
36 | const {
|
37 | footer
|
38 | } = await next(iterator, 'footer');
|
39 | const {
|
40 | header
|
41 | } = await next(iterator, 'header');
|
42 | const {
|
43 | blockCount
|
44 | } = await next(iterator, 'bat', 'parentLocator');
|
45 | return {
|
46 | blockSize: header.blockSize,
|
47 | blockCount,
|
48 | diskSize: footer.currentSize,
|
49 | geometry: footer.diskGeometry,
|
50 | blocks: onlyBlocks(iterator, header.blockSize)
|
51 | };
|
52 | }
|
53 |
|
\ | No newline at end of file |