check for out of order blocks in vhd output
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
"babel-preset-es2015": "^6.13.2",
|
||||
"babel-preset-stage-0": "^6.5.0",
|
||||
"chai": "^3.5.0",
|
||||
"chai-as-promised": "^5.3.0",
|
||||
"clarify": "^2.0.0",
|
||||
"dependency-check": "^2.6.0",
|
||||
"ghooks": "^1.3.2",
|
||||
|
||||
@@ -232,8 +232,11 @@ export class ReadableRawVHDStream extends stream.Readable {
|
||||
} else {
|
||||
const offset = next.lbaBytes
|
||||
const buffer = next.grain
|
||||
|
||||
const paddingBuffer = new Buffer(offset - this.position)
|
||||
var paddingLength = offset - this.position
|
||||
if (paddingLength < 0) {
|
||||
process.nextTick(() => this.emit('error', 'This VMDK file does not have its blocks in the correct order'))
|
||||
}
|
||||
const paddingBuffer = new Buffer(paddingLength)
|
||||
paddingBuffer.fill(0)
|
||||
if (paddingBuffer.length !== 0) {
|
||||
this.push(paddingBuffer)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
import {assert} from 'chai'
|
||||
import chai, {assert} from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
chai.use(chaiAsPromised)
|
||||
import {createWriteStream} from 'fs'
|
||||
import {describe, it} from 'mocha'
|
||||
import {exec} from 'child-process-promise'
|
||||
@@ -36,18 +38,16 @@ describe('VHD writing', () => {
|
||||
lbaBytes: 100,
|
||||
grain: new Buffer('azerzaerazeraze', 'ascii')
|
||||
}, {
|
||||
offset: 700,
|
||||
lbaBytes: 700,
|
||||
grain: new Buffer('gdfslkdfguer', 'ascii')
|
||||
}]
|
||||
let index = 0
|
||||
const mockParser = {
|
||||
next: async () => {
|
||||
if (index < data.length) {
|
||||
const promise = await new Promise((resolve) => {
|
||||
resolve(data[index])
|
||||
})
|
||||
const result = data[index]
|
||||
index++
|
||||
return promise
|
||||
return result
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
@@ -60,6 +60,34 @@ describe('VHD writing', () => {
|
||||
pipe.on('error', reject)
|
||||
})
|
||||
})
|
||||
it('ReadableRawVHDStream detects when blocks are out of order', async () => {
|
||||
const data = [{
|
||||
lbaBytes: 700,
|
||||
grain: new Buffer('azerzaerazeraze', 'ascii')
|
||||
}, {
|
||||
lbaBytes: 100,
|
||||
grain: new Buffer('gdfslkdfguer', 'ascii')
|
||||
}]
|
||||
let index = 0
|
||||
const mockParser = {
|
||||
next: async () => {
|
||||
if (index < data.length) {
|
||||
const result = data[index]
|
||||
index++
|
||||
return result
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
return assert.isRejected(new Promise((resolve, reject) => {
|
||||
const stream = new ReadableRawVHDStream(100000, mockParser)
|
||||
stream.on('error', reject)
|
||||
const pipe = stream.pipe(createWriteStream('outputStream'))
|
||||
pipe.on('finish', resolve)
|
||||
pipe.on('error', reject)
|
||||
}))
|
||||
})
|
||||
it('writing a known file is successful', async () => {
|
||||
const fileName = 'output.vhd'
|
||||
const rawFilename = 'output.raw'
|
||||
|
||||
Reference in New Issue
Block a user