|
| 1 | +import { promisify } from 'util'; |
1 | 2 | import { URL } from 'url';
|
2 | 3 | import { Link } from '../node';
|
3 | 4 | import Stats from '../Stats';
|
@@ -1431,4 +1432,41 @@ describe('volume', () => {
|
1431 | 1432 | expect(new StatWatcher(vol).vol).toBe(vol);
|
1432 | 1433 | });
|
1433 | 1434 | });
|
| 1435 | + describe('.createWriteStream', () => { |
| 1436 | + it('accepts filehandle as fd option', async () => { |
| 1437 | + const vol = new Volume(); |
| 1438 | + const fh = await vol.promises.open('/test.txt', 'wx', 0o600); |
| 1439 | + const writeStream = vol.createWriteStream('', { fd: fh }); |
| 1440 | + await promisify(writeStream.write.bind(writeStream))(Buffer.from('Hello')); |
| 1441 | + await promisify(writeStream.close.bind(writeStream))(); |
| 1442 | + expect(vol.toJSON()).toEqual({ |
| 1443 | + '/test.txt': 'Hello', |
| 1444 | + }); |
| 1445 | + }); |
| 1446 | + }); |
| 1447 | + describe('.createReadStream', () => { |
| 1448 | + it('accepts filehandle as fd option', done => { |
| 1449 | + const vol = Volume.fromJSON({ |
| 1450 | + '/test.txt': 'Hello', |
| 1451 | + }); |
| 1452 | + vol.promises |
| 1453 | + .open('/test.txt', 'r') |
| 1454 | + .then(fh => { |
| 1455 | + const readStream = vol.createReadStream('/this/should/be/ignored', { fd: fh }); |
| 1456 | + readStream.setEncoding('utf8'); |
| 1457 | + let readData = ''; |
| 1458 | + readStream.on('readable', () => { |
| 1459 | + const chunk = readStream.read(); |
| 1460 | + if (chunk != null) readData += chunk; |
| 1461 | + }); |
| 1462 | + readStream.on('end', () => { |
| 1463 | + expect(readData).toEqual('Hello'); |
| 1464 | + done(); |
| 1465 | + }); |
| 1466 | + }) |
| 1467 | + .catch(err => { |
| 1468 | + expect(err).toBeNull(); |
| 1469 | + }); |
| 1470 | + }); |
| 1471 | + }); |
1434 | 1472 | });
|
0 commit comments