UNPKG

2.07 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 _virtualBuffer = require('./virtual-buffer');
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23(0, _mocha.describe)('Virtual Buffer', function () {
24 var _this = this;
25
26 (0, _mocha.it)('can read a file correctly', (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
27 var rawFileName, buffer, part1, part2, original;
28 return _regenerator2.default.wrap(function _callee$(_context) {
29 while (1) {
30 switch (_context.prev = _context.next) {
31 case 0:
32 rawFileName = 'random-data';
33 _context.next = 3;
34 return (0, _childProcessPromise.exec)('base64 /dev/urandom | head -c 104448 > ' + rawFileName);
35
36 case 3:
37 buffer = new _virtualBuffer.VirtualBuffer((0, _fsPromise.createReadStream)(rawFileName));
38 _context.next = 6;
39 return buffer.readChunk(10);
40
41 case 6:
42 part1 = _context.sent;
43 _context.next = 9;
44 return buffer.readChunk(-1);
45
46 case 9:
47 part2 = _context.sent;
48 _context.next = 12;
49 return (0, _fsPromise.readFile)(rawFileName);
50
51 case 12:
52 original = _context.sent;
53
54 (0, _chai.assert)(buffer.isDepleted, 'virtual buffer is depleted');
55 _chai.assert.equal(Buffer.concat([part1, part2]).toString('ascii'), original.toString('ascii'));
56
57 case 15:
58 case 'end':
59 return _context.stop();
60 }
61 }
62 }, _callee, _this);
63 })));
64});
65//# sourceMappingURL=virtual-buffer.spec.js.map
\No newline at end of file