UNPKG

2.58 kBJavaScriptView Raw
1'use strict';
2
3var _regenerator = require('babel-runtime/regenerator');
4
5var _regenerator2 = _interopRequireDefault(_regenerator);
6
7var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
8
9var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
10
11var _chai = require('chai');
12
13var _fsPromise = require('fs-promise');
14
15var _mocha = require('mocha');
16
17var _childProcessPromise = require('child-process-promise');
18
19var _vmdkRead = require('./vmdk-read');
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23(0, _mocha.describe)('VMDK reading', function () {
24 (0, _mocha.it)('VMDKDirectParser reads OK', (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
25 var rawFileName, fileName, parser, header, harvested, res;
26 return _regenerator2.default.wrap(function _callee$(_context) {
27 while (1) {
28 switch (_context.prev = _context.next) {
29 case 0:
30 rawFileName = 'random-data';
31 fileName = 'random-data.vmdk';
32 _context.next = 4;
33 return (0, _childProcessPromise.exec)('base64 /dev/urandom | head -c 104448 > ' + rawFileName);
34
35 case 4:
36 _context.next = 6;
37 return (0, _childProcessPromise.exec)('rm -f ' + fileName + '&& VBoxManage convertfromraw --format VMDK --variant Stream ' + rawFileName + ' ' + fileName);
38
39 case 6:
40 parser = new _vmdkRead.VMDKDirectParser((0, _fsPromise.createReadStream)(fileName));
41 _context.next = 9;
42 return parser.readHeader();
43
44 case 9:
45 header = _context.sent;
46 harvested = [];
47
48 case 11:
49 if (!true) {
50 _context.next = 20;
51 break;
52 }
53
54 _context.next = 14;
55 return parser.next();
56
57 case 14:
58 res = _context.sent;
59
60 if (!(res === null)) {
61 _context.next = 17;
62 break;
63 }
64
65 return _context.abrupt('break', 20);
66
67 case 17:
68 harvested.push(res);
69 _context.next = 11;
70 break;
71
72 case 20:
73 _chai.assert.equal(harvested.length, 2);
74 _chai.assert.equal(harvested[0].lba, 0);
75 _chai.assert.equal(harvested[1].lba, header['grainSizeSectors']);
76
77 case 23:
78 case 'end':
79 return _context.stop();
80 }
81 }
82 }, _callee, undefined);
83 }))).timeout(10000);
84});
85//# sourceMappingURL=vmdk-read.spec.js.map
\No newline at end of file