@@ -59,16 +59,20 @@ function headersInvalid (headers) {
59
59
if ( headers [ 'accept-ranges' ] !== 'bytes' ) return true
60
60
}
61
61
62
- RandomAccessHTTP . prototype . write = function ( offset , data , cb ) {
62
+ RandomAccessHTTP . prototype . write = function ( offset , buf , cb ) {
63
63
if ( ! cb ) cb = noop
64
+ if ( ! this . opened ) return openAndWrite ( this , offset , buf , cb )
64
65
if ( ! this . writable ) return cb ( new Error ( 'URL is not writable' ) )
65
66
cb ( new Error ( 'Write Not Implemented' ) )
66
67
}
67
68
68
69
RandomAccessHTTP . prototype . read = function ( offset , length , cb ) {
69
70
if ( ! this . opened ) return openAndRead ( this , offset , length , cb )
70
71
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 )
72
76
}
73
77
74
78
RandomAccessHTTP . prototype . close = function ( cb ) {
@@ -85,3 +89,10 @@ function openAndRead (self, offset, length, cb) {
85
89
self . read ( offset , length , cb )
86
90
} )
87
91
}
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