UNPKG

7.16 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","names":["_asyncIteratorToStream","_interopRequireDefault","require","_createReadableSparseStream","_ovaRead","_vmdkRead","_vmdkGenerate","_ovaGenerate","_parseVhdToBlocks","_vmdkReadTable","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","vmdkToVhd","vmdkReadStream","grainLogicalAddressList","grainFileOffsetList","gzipped","length","parser","VMDKDirectParser","header","readHeader","vhdStream","createReadableSparseStream","capacitySectors","grainSizeSectors","blockIterator","_rawLength","descriptor","extents","size","computeVmdkLength","diskName","vhdReadStream","iterator","vhdToVMDKIterator","b","vhdToVMDK","vhdReadStreamGetter","withLength","stream","asyncIteratorToStream","undefined","blockSize","blockCount","blocks","diskSize","geometry","parseVhdToBlocks","dataSize","metadataSize","generateVmdkData"],"sources":["../src/index.js"],"sourcesContent":["import asyncIteratorToStream from 'async-iterator-to-stream'\nimport createReadableSparseStream from 'vhd-lib/createReadableSparseStream.js'\nimport { parseOVAFile, ParsableFile } from './ova-read'\nimport VMDKDirectParser from './vmdk-read'\nimport { generateVmdkData } from './vmdk-generate'\nimport { writeOvaOn } from './ova-generate'\nimport { parseVhdToBlocks } from './parseVhdToBlocks'\n\nexport { default as readVmdkGrainTable, readCapacityAndGrainTable } from './vmdk-read-table'\n\n/**\n *\n * @param vmdkReadStream\n * @param grainLogicalAddressList iterable of LBAs in VMDK grain size\n * @param grainFileOffsetList iterable of offsets in sectors (512 bytes)\n * @param gzipped\n * @returns a stream whose bytes represent a VHD file containing the VMDK data\n */\nasync function vmdkToVhd(vmdkReadStream, grainLogicalAddressList, grainFileOffsetList, gzipped = false, length) {\n const parser = new VMDKDirectParser(vmdkReadStream, grainLogicalAddressList, grainFileOffsetList, gzipped, length)\n const header = await parser.readHeader()\n const vhdStream = await createReadableSparseStream(\n header.capacitySectors * 512,\n header.grainSizeSectors * 512,\n grainLogicalAddressList,\n parser.blockIterator()\n )\n vhdStream._rawLength = parser.descriptor.extents[0].size\n return vhdStream\n}\n\nexport async function computeVmdkLength(diskName, vhdReadStream) {\n let length = 0\n const { iterator } = await vhdToVMDKIterator(diskName, vhdReadStream)\n for await (const b of iterator) {\n length += b.length\n }\n return length\n}\n\n/**\n * @param diskName\n * @param vhdReadStreamGetter an async function whose call brings a fresh VHD readStream.\n * We need to read the VHD twice when generating OVA files to get the VMDK file length.\n * @param withLength if true, the returned VMDK stream will have its `length` field set. The VHD stream will be entirely read to compute it.\n * @returns a readable stream representing a VMDK file\n */\nexport async function vhdToVMDK(diskName, vhdReadStreamGetter, withLength = false) {\n const { iterator, size } = await vhdToVMDKIterator(diskName, await vhdReadStreamGetter())\n let length\n const stream = await asyncIteratorToStream(iterator)\n if (withLength) {\n if (size === undefined) {\n length = await computeVmdkLength(diskName, await vhdReadStreamGetter())\n } else {\n length = size\n }\n stream.length = length\n }\n return stream\n}\n\n/**\n * the returned stream will have its length set IIF compress === false\n * @param diskName\n * @param vhdReadStream\n * @returns a readable stream representing a VMDK file\n */\nexport async function vhdToVMDKIterator(diskName, vhdReadStream) {\n const { blockSize, blockCount, blocks, diskSize, geometry } = await parseVhdToBlocks(vhdReadStream)\n\n const dataSize = blockSize * blockCount\n const { iterator, metadataSize } = await generateVmdkData(diskName, diskSize, blockSize, blocks, geometry, dataSize)\n return {\n iterator,\n size: dataSize + metadataSize,\n }\n}\n\nexport { ParsableFile, parseOVAFile, vmdkToVhd, writeOvaOn }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,sBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,2BAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAC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