Skip to content

Commit 5d74c44

Browse files
committed
Stub out read and write
1 parent 3d6b447 commit 5d74c44

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ function headersInvalid (headers) {
6161

6262
RandomAccessHTTP.prototype.write = function (offset, data, cb) {
6363
if (!cb) cb = noop
64-
if (!this.buffer) return cb(new Error('Instance is closed'))
64+
if (!this.writable) return cb(new Error('URL is not writable'))
6565
cb(new Error('Write Not Implemented'))
6666
}
6767

6868
RandomAccessHTTP.prototype.read = function (offset, length, cb) {
69-
if (!this.buffer) return cb(new Error('Instance is closed'))
70-
if (offset + length > this.buffer.length) return cb(new Error('Could not satisfy length'))
69+
if (!this.opened) return openAndRead(this, offset, length, cb)
70+
if (!this.readable) return cb(new Error('File is not readable'))
7171
cb(new Error('Read Not Implemented'))
7272
}
7373

@@ -78,3 +78,10 @@ RandomAccessHTTP.prototype.close = function (cb) {
7878
}
7979

8080
function noop () {}
81+
82+
function openAndRead (self, offset, length, cb) {
83+
self.open(function (err) {
84+
if (err) return cb(err)
85+
self.read(offset, length, cb)
86+
})
87+
}

0 commit comments

Comments
 (0)