@@ -59,6 +59,7 @@ export default class TarballFetcher extends BaseFetcher {
59
59
if ( parts . protocol === null ) {
60
60
// path to the local tarball
61
61
let localTarball ;
62
+ let isOfflineTarball = false ;
62
63
63
64
let relativeFileLoc = parts . pathname && path . join ( this . config . cwd , parts . pathname ) ;
64
65
if ( relativeFileLoc && await fsUtil . exists ( relativeFileLoc ) ) {
@@ -67,6 +68,7 @@ export default class TarballFetcher extends BaseFetcher {
67
68
} else {
68
69
// generate a offline cache location
69
70
localTarball = path . resolve ( this . config . getOfflineMirrorPath ( registry , null ) , ref ) ;
71
+ isOfflineTarball = true ;
70
72
}
71
73
72
74
if ( ! ( await fsUtil . exists ( localTarball ) ) ) {
@@ -78,9 +80,25 @@ export default class TarballFetcher extends BaseFetcher {
78
80
79
81
// flow gets confused with the pipe/on types chain
80
82
let cachedStream : Object = fs . createReadStream ( localTarball ) ;
83
+
84
+ let decompressStream = zlib . createUnzip ( ) ;
85
+
86
+ // nicer errors for corrupted compressed tarballs
87
+ decompressStream . on ( "error" , function ( err ) {
88
+ let msg = `${ err . message } . ` ;
89
+ if ( isOfflineTarball ) {
90
+ msg += `Mirror tarball appears to be corrupt. You can resolve this by running:\n\n` +
91
+ ` $ rm -rf ${ localTarball } \n` +
92
+ " $ kpm install --save" ;
93
+ } else {
94
+ msg += `Error decompressing ${ localTarball } , it appears to be corrupt.` ;
95
+ }
96
+ reject ( new MessageError ( msg ) ) ;
97
+ } ) ;
98
+
81
99
cachedStream
82
100
. pipe ( validateStream )
83
- . pipe ( zlib . createUnzip ( ) )
101
+ . pipe ( decompressStream )
84
102
. on ( "error" , reject )
85
103
. pipe ( extractor ) ;
86
104
} ) ;
0 commit comments