Skip to content

Commit 6f7a14f

Browse files
authored
also test for readonly sparse (#37)
* also test for readonly sparse * pin brittle to 3.1.3 * actually pin * check sparse error * try to fix
1 parent a289541 commit 6f7a14f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module.exports = class RandomAccessFile extends RandomAccessStorage {
108108
function onlock (err) {
109109
if (err) return onerrorafteropen(err)
110110

111-
if (!self._sparse || !fsext) return onsparse(null)
111+
if (!self._sparse || !fsext || self.mode === RDONLY) return onsparse(null)
112112

113113
fsext.sparse(self.fd).then(onsparse, onsparse)
114114
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"fs-native-extensions": "^1.1.0"
1919
},
2020
"devDependencies": {
21-
"brittle": "^3.0.4",
21+
"brittle": "^3.3.0",
2222
"standard": "^17.0.0"
2323
},
2424
"repository": {

test/basic.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,24 @@ test('readonly mode', function (t) {
502502
})
503503
})
504504

505+
test('readonly mode + sparse', function (t) {
506+
t.plan(1)
507+
508+
const filename = gen()
509+
const f = new RAF(filename, { sparse: true })
510+
511+
f.write(0, Buffer.from('hello world'), function () {
512+
f.close(function () {
513+
const r = new RAF(filename, { writable: false, sparse: true })
514+
515+
r.read(0, 5, function (_, data) {
516+
t.alike(data, Buffer.from('hello'))
517+
r.close()
518+
})
519+
})
520+
})
521+
})
522+
505523
function gen () {
506524
return path.join(tmp, ++i + '.txt')
507525
}

0 commit comments

Comments
 (0)