UNPKG

4.12 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6Object.defineProperty(exports, "ParsableFile", {
7 enumerable: true,
8 get: function () {
9 return _ovaRead.ParsableFile;
10 }
11});
12exports.computeVmdkLength = computeVmdkLength;
13Object.defineProperty(exports, "parseOVAFile", {
14 enumerable: true,
15 get: function () {
16 return _ovaRead.parseOVAFile;
17 }
18});
19Object.defineProperty(exports, "readCapacityAndGrainTable", {
20 enumerable: true,
21 get: function () {
22 return _vmdkReadTable.readCapacityAndGrainTable;
23 }
24});
25Object.defineProperty(exports, "readVmdkGrainTable", {
26 enumerable: true,
27 get: function () {
28 return _vmdkReadTable.default;
29 }
30});
31exports.vhdToVMDK = vhdToVMDK;
32exports.vhdToVMDKIterator = vhdToVMDKIterator;
33exports.vmdkToVhd = vmdkToVhd;
34Object.defineProperty(exports, "writeOvaOn", {
35 enumerable: true,
36 get: function () {
37 return _ovaGenerate.writeOvaOn;
38 }
39});
40var _asyncIteratorToStream = _interopRequireDefault(require("async-iterator-to-stream"));
41var _createReadableSparseStream = _interopRequireDefault(require("vhd-lib/createReadableSparseStream.js"));
42var _ovaRead = require("./ova-read");
43var _vmdkRead = _interopRequireDefault(require("./vmdk-read"));
44var _vmdkGenerate = require("./vmdk-generate");
45var _ovaGenerate = require("./ova-generate");
46var _parseVhdToBlocks = require("./parseVhdToBlocks");
47var _vmdkReadTable = _interopRequireWildcard(require("./vmdk-read-table"));
48function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
49function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
50function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51async function vmdkToVhd(vmdkReadStream, grainLogicalAddressList, grainFileOffsetList, gzipped = false, length) {
52 const parser = new _vmdkRead.default(vmdkReadStream, grainLogicalAddressList, grainFileOffsetList, gzipped, length);
53 const header = await parser.readHeader();
54 const vhdStream = await (0, _createReadableSparseStream.default)(header.capacitySectors * 512, header.grainSizeSectors * 512, grainLogicalAddressList, parser.blockIterator());
55 vhdStream._rawLength = parser.descriptor.extents[0].size;
56 return vhdStream;
57}
58async function computeVmdkLength(diskName, vhdReadStream) {
59 let length = 0;
60 const {
61 iterator
62 } = await vhdToVMDKIterator(diskName, vhdReadStream);
63 for await (const b of iterator) {
64 length += b.length;
65 }
66 return length;
67}
68async function vhdToVMDK(diskName, vhdReadStreamGetter, withLength = false) {
69 const {
70 iterator,
71 size
72 } = await vhdToVMDKIterator(diskName, await vhdReadStreamGetter());
73 let length;
74 const stream = await (0, _asyncIteratorToStream.default)(iterator);
75 if (withLength) {
76 if (size === undefined) {
77 length = await computeVmdkLength(diskName, await vhdReadStreamGetter());
78 } else {
79 length = size;
80 }
81 stream.length = length;
82 }
83 return stream;
84}
85async function vhdToVMDKIterator(diskName, vhdReadStream) {
86 const {
87 blockSize,
88 blockCount,
89 blocks,
90 diskSize,
91 geometry
92 } = await (0, _parseVhdToBlocks.parseVhdToBlocks)(vhdReadStream);
93 const dataSize = blockSize * blockCount;
94 const {
95 iterator,
96 metadataSize
97 } = await (0, _vmdkGenerate.generateVmdkData)(diskName, diskSize, blockSize, blocks, geometry, dataSize);
98 return {
99 iterator,
100 size: dataSize + metadataSize
101 };
102}
103//# sourceMappingURL=index.js.map
\No newline at end of file