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BAAS,WAAT,CAf0B;;AAAA;AAe9C,uBAf8C;;AAgBpD,yBAAO,KAAP,CAAa,YAAY,MAAzB,EAAiC,QAAjC;AACA,iBAAS,CAAT,GAAa,CAAb,EAAgB,IAAI,YAAY,MAAhC,EAAwC,GAAxC,EAA6C;AAC3C,kBAAI,YAAY,CAAZ,MAAmB,OAAO,CAAP,CAAvB,EAAkC;AAChC,6BAAO,IAAP,CAAY,YAAY,CAAZ,CAAZ,EAA4B,CAA5B;AACD;AACF;;AArBmD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAtD;AAuBD,CA9FD","file":"vhd-write.spec.js","sourcesContent":["'use strict'\n\nimport chai, {assert} from 'chai'\nimport chaiAsPromised from 'chai-as-promised'\nchai.use(chaiAsPromised)\nimport {createWriteStream} from 'fs'\nimport {describe, it} from 'mocha'\nimport {exec} from 'child-process-promise'\nimport {readFile} from 'fs-promise'\n\nimport {\n computeChecksum,\n computeGeometryForSize,\n createDynamicDiskHeader,\n createFooter,\n ReadableRawVHDStream,\n VHDFile\n} from './vhd-write'\n\ndescribe('VHD writing', () => {\n it('computeChecksum() is correct against some reference values', () => {\n // those values were taken from a file generated by qemu\n const testValue1 = '636F6E6563746978000000020001000000000000000002001F34DB9F71656D75000500035769326B0000000000019800000000000001980000030411000000030000000033B3A5E17F94433498376740246E5660'\n const expectedChecksum1 = 0xFFFFEFB2\n const testValue2 = '6378737061727365FFFFFFFFFFFFFFFF0000000000000600000100000000000100200000'\n const expectedChecksum2 = 0xFFFFF476\n assert.equal(computeChecksum(new Buffer(testValue1, 'hex')), expectedChecksum1)\n assert.equal(computeChecksum(new Buffer(testValue2, 'hex')), expectedChecksum2)\n })\n it('createFooter() does not crash', () => {\n createFooter(104448, Math.floor(Date.now() / 1000), {cylinders: 3, heads: 4, sectorsPerTrack: 17})\n })\n it('createDynamicDiskHeader() does not crash', () => {\n createDynamicDiskHeader(1, 0x00200000)\n })\n it('ReadableRawVHDStream does not crash', async () => {\n const data = [{\n lbaBytes: 100,\n grain: new Buffer('azerzaerazeraze', 'ascii')\n }, {\n lbaBytes: 700,\n grain: new Buffer('gdfslkdfguer', 'ascii')\n }]\n let index = 0\n const mockParser = {\n next: async () => {\n if (index < data.length) {\n const result = data[index]\n index++\n return result\n } else {\n return null\n }\n }\n }\n const stream = new ReadableRawVHDStream(100000, mockParser)\n const pipe = stream.pipe(createWriteStream('outputStream'))\n await new Promise((resolve, reject) => {\n pipe.on('finish', resolve)\n pipe.on('error', reject)\n })\n })\n it('ReadableRawVHDStream detects when blocks are out of order', async () => {\n const data = [{\n lbaBytes: 700,\n grain: new Buffer('azerzaerazeraze', 'ascii')\n }, {\n lbaBytes: 100,\n grain: new Buffer('gdfslkdfguer', 'ascii')\n }]\n let index = 0\n const mockParser = {\n next: async () => {\n if (index < data.length) {\n const result = data[index]\n index++\n return result\n } else {\n return null\n }\n }\n }\n return assert.isRejected(new Promise((resolve, reject) => {\n const stream = new ReadableRawVHDStream(100000, mockParser)\n stream.on('error', reject)\n const pipe = stream.pipe(createWriteStream('outputStream'))\n pipe.on('finish', resolve)\n pipe.on('error', reject)\n }))\n })\n it('writing a known file with VHDFile is successful', async () => {\n const fileName = 'output.vhd'\n const rawFilename = 'output.raw'\n const randomFileName = 'random.raw'\n const geometry = computeGeometryForSize(1024 * 1024 * 8)\n const dataSize = geometry.actualSize\n await exec('base64 /dev/urandom | head -c ' + dataSize + ' > ' + randomFileName)\n const buffer = await readFile(randomFileName)\n const f = new VHDFile(buffer.length, 523557791)\n const splitPoint = Math.floor(Math.random() * buffer.length)\n f.writeBuffer(buffer.slice(splitPoint), splitPoint)\n f.writeBuffer(buffer.slice(0, splitPoint), 0)\n f.writeBuffer(buffer.slice(splitPoint), splitPoint)\n await f.writeFile(fileName)\n await exec('qemu-img convert -fvpc -Oraw ' + fileName + ' ' + rawFilename)\n const fileContent = await readFile(rawFilename)\n assert.equal(fileContent.length, dataSize)\n for (let i = 0; i < fileContent.length; i++) {\n if (fileContent[i] !== buffer[i]) {\n assert.fail(fileContent[i], 0)\n }\n }\n })\n})\n"]} |