Skip to content

Commit efc28cc

Browse files
committed
Stared poking at the read method
1 parent 5d74c44 commit efc28cc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@ function headersInvalid (headers) {
5959
if (headers['accept-ranges'] !== 'bytes') return true
6060
}
6161

62-
RandomAccessHTTP.prototype.write = function (offset, data, cb) {
62+
RandomAccessHTTP.prototype.write = function (offset, buf, cb) {
6363
if (!cb) cb = noop
64+
if (!this.opened) return openAndWrite(this, offset, buf, cb)
6465
if (!this.writable) return cb(new Error('URL is not writable'))
6566
cb(new Error('Write Not Implemented'))
6667
}
6768

6869
RandomAccessHTTP.prototype.read = function (offset, length, cb) {
6970
if (!this.opened) return openAndRead(this, offset, length, cb)
7071
if (!this.readable) return cb(new Error('File is not readable'))
71-
cb(new Error('Read Not Implemented'))
72+
73+
var buf = Buffer(length)
74+
75+
if (!length) return cb(null, buf)
7276
}
7377

7478
RandomAccessHTTP.prototype.close = function (cb) {
@@ -85,3 +89,10 @@ function openAndRead (self, offset, length, cb) {
8589
self.read(offset, length, cb)
8690
})
8791
}
92+
93+
function openAndWrite (self, offset, buf, cb) {
94+
self.open(function (err) {
95+
if (err) return cb(err)
96+
self.write(offset, buf, cb)
97+
})
98+
}

0 commit comments

Comments
 (0)