File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -156,19 +156,24 @@ Blobs.prototype.createReadStream = function (opts) {
156
156
return server . get ( key )
157
157
} )
158
158
. then ( function ( result ) {
159
- if ( ! result ) throw new Error ( 'key not found: ' + key )
160
-
159
+ if ( ! result ) {
160
+ throw new Error ( 'key not found: ' + key )
161
+ }
161
162
buf = result
162
163
var nextPart = buf . pop ( )
163
-
164
+ if ( isUndefined ( nextPart ) ) {
165
+ return next ( null , new Buffer ( 0 ) )
166
+ }
164
167
next ( null , toBuffer ( nextPart ) )
165
168
} )
166
169
. catch ( function ( err ) {
167
170
next ( err )
168
171
} )
169
172
}
170
173
171
- if ( buf . length === 0 ) return next ( null , null )
174
+ if ( buf . length === 0 ) {
175
+ return next ( null , null )
176
+ }
172
177
173
178
next ( null , toBuffer ( buf . pop ( ) ) )
174
179
} )
Original file line number Diff line number Diff line change @@ -89,5 +89,25 @@ describe('idb-plus-blob-store', () => {
89
89
ws . write ( 'hello' )
90
90
ws . end ( )
91
91
} )
92
+ it ( 'read an empty blob' , ( done ) => {
93
+ const name = 'hello.txt'
94
+ const ws = store . createWriteStream ( { name} , ( err , blob ) => {
95
+ expect ( err ) . to . not . exist
96
+ expect ( blob . key ) . to . be . eql ( name )
97
+
98
+ const rs = store . createReadStream ( { name} )
99
+
100
+ rs . pipe ( bl ( ( err , res ) => {
101
+ expect ( err ) . to . not . exist
102
+ expect ( res . length ) . to . equal ( 0 )
103
+ expect ( res ) . to . be . eql ( new Buffer ( 0 ) )
104
+
105
+ done ( )
106
+ } ) )
107
+ } )
108
+
109
+ ws . write ( new Buffer ( 0 ) )
110
+ ws . end ( )
111
+ } )
92
112
} )
93
113
} )
You can’t perform that action at this time.
0 commit comments