This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,29 @@ module.exports = (common, options) => {
113113 expect ( accumProgress ) . to . equal ( fixtures . bigFile . data . length )
114114 } )
115115
116+ it ( 'should add an empty file with progress enabled' , async ( ) => {
117+ let progCalled = false
118+ let accumProgress = 0
119+ function handler ( p ) {
120+ progCalled = true
121+ accumProgress = p
122+ }
123+
124+ const file = await ipfs . add ( fixtures . emptyFile . data , { progress : handler } )
125+
126+ expect ( file . cid . toString ( ) ) . to . equal ( fixtures . emptyFile . cid )
127+ expect ( file . path ) . to . equal ( fixtures . emptyFile . cid )
128+ expect ( progCalled ) . to . be . true ( )
129+ expect ( accumProgress ) . to . equal ( fixtures . emptyFile . data . length )
130+ } )
131+
132+ it ( 'should add an empty file without progress enabled' , async ( ) => {
133+ const file = await ipfs . add ( fixtures . emptyFile . data )
134+
135+ expect ( file . cid . toString ( ) ) . to . equal ( fixtures . emptyFile . cid )
136+ expect ( file . path ) . to . equal ( fixtures . emptyFile . cid )
137+ } )
138+
116139 it ( 'should add a Buffer as tuple' , async ( ) => {
117140 const tuple = { path : 'testfile.txt' , content : fixtures . smallFile . data }
118141
Original file line number Diff line number Diff line change @@ -21,5 +21,9 @@ exports.fixtures = Object.freeze({
2121 bigFile : Object . freeze ( {
2222 cid : 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' ,
2323 data : loadFixture ( 'test/fixtures/15mb.random' , 'interface-ipfs-core' )
24+ } ) ,
25+ emptyFile : Object . freeze ( {
26+ cid : 'QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH' ,
27+ data : new Uint8Array ( 0 )
2428 } )
2529} )
Original file line number Diff line number Diff line change @@ -32,10 +32,10 @@ module.exports = configure((api) => {
3232 for await ( let file of res . ndjson ( ) ) {
3333 file = toCamel ( file )
3434
35- if ( progressFn && file . bytes ) {
36- progressFn ( file . bytes )
37- } else {
35+ if ( file . hash !== undefined ) {
3836 yield toCoreInterface ( file )
37+ } else if ( progressFn ) {
38+ progressFn ( file . bytes || 0 )
3939 }
4040 }
4141 }
You can’t perform that action at this time.
0 commit comments