Skip to content

Commit b576e46

Browse files
Fix deleting [0, Infinity) (#31)
* Add failing test case * Fix it * Update basic.js Co-authored-by: Mathias Buus <[email protected]>
1 parent fe815f2 commit b576e46

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ module.exports = class RandomAccessFile extends RandomAccessStorage {
153153
}
154154

155155
_del (req) {
156+
if (req.size === Infinity) return this._truncate(req) // TODO: remove this when all callsites use truncate
157+
156158
if (!fsext) return req.callback(null)
157159

158160
fsext.trim(this.fd, req.offset, req.size).then(ontrim, ontrim)

test/basic.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,22 @@ test('del, partial and whole', function (t) {
322322
})
323323
})
324324

325+
// TODO: remove this test when we deprecate this usage of delete
326+
test('del, infinity', function (t) {
327+
t.plan(4)
328+
329+
const file = new RAF(gen(), { size: 100 })
330+
331+
file.del(0, Infinity, function (err) {
332+
t.absent(err, 'no error')
333+
file.stat(function (err, st) {
334+
t.absent(err, 'no error')
335+
t.is(st.size, 0)
336+
file.destroy(() => t.pass())
337+
})
338+
})
339+
})
340+
325341
test('truncate', function (t) {
326342
t.plan(7)
327343

0 commit comments

Comments
 (0)