@@ -37,6 +37,7 @@ function putStream (cache, key, opts = {}) {
37
37
opts = putOpts ( opts )
38
38
let integrity
39
39
let size
40
+ let error
40
41
41
42
let memoData
42
43
const pipeline = new Pipeline ( )
@@ -58,28 +59,33 @@ function putStream (cache, key, opts = {}) {
58
59
. on ( 'size' , ( s ) => {
59
60
size = s
60
61
} )
62
+ . on ( 'error' , ( err ) => {
63
+ error = err
64
+ } )
61
65
62
66
pipeline . push ( contentStream )
63
67
64
68
// last but not least, we write the index and emit hash and size,
65
69
// and memoize if we're doing that
66
70
pipeline . push ( new Flush ( {
67
71
flush ( ) {
68
- return index
69
- . insert ( cache , key , integrity , { ...opts , size } )
70
- . then ( ( entry ) => {
71
- if ( memoize && memoData ) {
72
- memo . put ( cache , entry , memoData , opts )
73
- }
72
+ if ( ! error ) {
73
+ return index
74
+ . insert ( cache , key , integrity , { ...opts , size } )
75
+ . then ( ( entry ) => {
76
+ if ( memoize && memoData ) {
77
+ memo . put ( cache , entry , memoData , opts )
78
+ }
74
79
75
- if ( integrity ) {
76
- pipeline . emit ( 'integrity' , integrity )
77
- }
80
+ if ( integrity ) {
81
+ pipeline . emit ( 'integrity' , integrity )
82
+ }
78
83
79
- if ( size ) {
80
- pipeline . emit ( 'size' , size )
81
- }
82
- } )
84
+ if ( size ) {
85
+ pipeline . emit ( 'size' , size )
86
+ }
87
+ } )
88
+ }
83
89
} ,
84
90
} ) )
85
91
0 commit comments