mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
As a first step to porting portions of the pino structured logger into the runtime, this commit ports the SonicBoom module to the fs module as Utf8Stream. This is a faithful port of the SonicBoom module with some modern updates, such as converting to a Class and using Symbol.dispose. The bulk of the implementation is unchanged from the original. PR-URL: https://github.com/nodejs/node/pull/58897 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const tmpdir = require('../common/tmpdir');
|
|
const {
|
|
ok,
|
|
throws,
|
|
} = require('node:assert');
|
|
const {
|
|
closeSync,
|
|
openSync,
|
|
} = require('node:fs');
|
|
const { Utf8Stream } = require('node:fs');
|
|
const { join } = require('node:path');
|
|
|
|
tmpdir.refresh();
|
|
let fileCounter = 0;
|
|
|
|
function getTempFile() {
|
|
return join(tmpdir.path, `fastutf8stream-${process.pid}-${Date.now()}-${fileCounter++}.log`);
|
|
}
|
|
|
|
const MAX_WRITE = 16 * 1024;
|
|
|
|
{
|
|
const dest = getTempFile();
|
|
const stream = new Utf8Stream({ dest, sync: false, minLength: 9999 });
|
|
|
|
ok(stream.write(Buffer.alloc(1500).fill('x').toString()));
|
|
ok(stream.write(Buffer.alloc(1500).fill('x').toString()));
|
|
ok(!stream.write(Buffer.alloc(MAX_WRITE).fill('x').toString()));
|
|
|
|
stream.on('drain', common.mustCall(() => stream.end()));
|
|
|
|
}
|
|
|
|
{
|
|
const dest = getTempFile();
|
|
const fd = openSync(dest, 'w');
|
|
|
|
throws(() => {
|
|
new Utf8Stream({
|
|
fd,
|
|
minLength: MAX_WRITE
|
|
});
|
|
}, Error);
|
|
|
|
closeSync(fd);
|
|
}
|