Skip to content

Commit

Permalink
make tests fast and add tiny chunk test
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Nov 1, 2023
1 parent f5d61e6 commit e061fd4
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

Expand All @@ -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)

Expand Down

0 comments on commit e061fd4

Please sign in to comment.