File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -122,11 +122,26 @@ class Hyperblobs {
122
122
} )
123
123
}
124
124
125
- async get ( id , opts ) {
125
+ async _getAll ( id , opts ) {
126
126
if ( id . blockLength === 1 ) return this . core . get ( id . blockOffset , opts )
127
127
128
- const res = [ ]
128
+ const promises = new Array ( id . blockLength )
129
+ for ( let i = 0 ; i < id . blockLength ; i ++ ) {
130
+ promises [ i ] = this . core . get ( id . blockOffset + i , opts )
131
+ }
129
132
133
+ const blocks = await Promise . all ( promises )
134
+ for ( let i = 0 ; i < id . blockLength ; i ++ ) {
135
+ if ( blocks [ i ] === null ) return null
136
+ }
137
+ return b4a . concat ( blocks )
138
+ }
139
+
140
+ async get ( id , opts ) {
141
+ const all = ! opts || ( ! opts . start && opts . length === undefined && opts . end === undefined && ! opts . core )
142
+ if ( all ) return this . _getAll ( id , opts )
143
+
144
+ const res = [ ]
130
145
try {
131
146
for await ( const block of this . createReadStream ( id , opts ) ) {
132
147
res . push ( block )
You can’t perform that action at this time.
0 commit comments