From e061fd4b82a5703d3034d66b8ee0113ab456cfbe Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Wed, 1 Nov 2023 19:39:01 +0100 Subject: [PATCH] make tests fast and add tiny chunk test --- test/basic.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/basic.js b/test/basic.js index 10b0263..d0e80a6 100644 --- a/test/basic.js +++ b/test/basic.js @@ -179,14 +179,14 @@ test('write/read big chunks', async function (t) { io.absent(err, 'no error') file.read(0, bigBuffer.length, function (err, buf) { io.absent(err, 'no error') - io.alike(buf, bigBuffer) + io.ok(buf.equals(bigBuffer)) }) }) file.write(bigBuffer.length * 2, bigBuffer, function (err) { io.absent(err, 'no error') file.read(bigBuffer.length * 2, bigBuffer.length, function (err, buf) { io.absent(err, 'no error') - io.alike(buf, bigBuffer) + io.ok(buf.equals(bigBuffer)) }) }) @@ -195,6 +195,29 @@ test('write/read big chunks', async function (t) { file.unlink(() => t.pass()) }) +test('read tons of small chunks', function (t) { + t.plan(1) + const file = new RAF(gen()) + const bigBuffer = Buffer.alloc(10 * 1024 * 1024) + let same = true + + bigBuffer.fill('hey. hey. how are you doing?. i am good thanks how about you? i am good') + + file.write(0, bigBuffer, function () { + let offset = 0 + file.read(offset, 128, function loop (_, buf) { + if (same) same = buf.equals(bigBuffer.subarray(offset, offset + 128)) + offset += 128 + if (offset >= bigBuffer.byteLength) { + t.ok(same, 'all sub chunks match') + t.end() + } else { + file.read(offset, 128, loop) + } + }) + }) +}) + test('rmdir option', function (t) { t.plan(5)