File tree Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Original file line number Diff line number Diff line change 1
1
const mutexify = require ( 'mutexify' )
2
+ const b4a = require ( 'b4a' )
2
3
3
4
const { BlobReadStream, BlobWriteStream } = require ( './lib/streams' )
4
5
@@ -22,12 +23,12 @@ module.exports = class Hyperblobs {
22
23
}
23
24
24
25
async put ( blob , opts ) {
25
- if ( ! Buffer . isBuffer ( blob ) ) blob = Buffer . from ( blob )
26
+ if ( ! b4a . isBuffer ( blob ) ) blob = b4a . from ( blob )
26
27
const blockSize = ( opts && opts . blockSize ) || this . blockSize
27
28
28
29
const stream = this . createWriteStream ( opts )
29
30
for ( let i = 0 ; i < blob . length ; i += blockSize ) {
30
- stream . write ( blob . slice ( i , i + blockSize ) )
31
+ stream . write ( blob . subarray ( i , i + blockSize ) )
31
32
}
32
33
stream . end ( )
33
34
@@ -42,7 +43,8 @@ module.exports = class Hyperblobs {
42
43
for await ( const block of this . createReadStream ( id , opts ) ) {
43
44
res . push ( block )
44
45
}
45
- return Buffer . concat ( res )
46
+ if ( res . length === 1 ) return res [ 0 ]
47
+ return b4a . concat ( res )
46
48
}
47
49
48
50
createReadStream ( id , opts ) {
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ class BlobReadStream extends Readable {
148
148
149
149
const remainder = this . _end - this . _pos
150
150
if ( this . _relativeOffset || ( remainder < block . length ) ) {
151
- block = block . slice ( this . _relativeOffset , this . _relativeOffset + remainder )
151
+ block = block . subarray ( this . _relativeOffset , this . _relativeOffset + remainder )
152
152
}
153
153
154
154
this . _index ++
Original file line number Diff line number Diff line change 22
22
},
23
23
"homepage" : " https://github.com/hypercore-protocol/hyperblobs#readme" ,
24
24
"dependencies" : {
25
+ "b4a" : " ^1.6.1" ,
25
26
"mutexify" : " ^1.4.0" ,
26
27
"streamx" : " ^2.12.4"
27
28
},
28
29
"devDependencies" : {
30
+ "brittle" : " ^3.1.0" ,
29
31
"hypercore" : " ^10.0.0" ,
30
32
"random-access-memory" : " ^6.0.0" ,
31
- "standard" : " ^17.0.0" ,
32
- "brittle" : " ^3.1.0"
33
+ "standard" : " ^17.0.0"
33
34
}
34
35
}
You can’t perform that action at this time.
0 commit comments