@@ -63,23 +63,93 @@ that all of the data is immediately available by calling
63
63
` stream.read() ` . For writable streams, it will be acted upon as soon
64
64
as it is provided, but this can be at any time.
65
65
66
- ### Warnings
67
-
68
- Some things cause tar to emit a warning, but should usually not cause
69
- the entire operation to fail. There are three ways to handle
70
- warnings:
71
-
72
- 1 . ** Ignore them** (default) Invalid entries won't be put in the
73
- archive, and invalid entries won't be unpacked. This is usually
74
- fine, but can hide failures that you might care about.
75
- 2 . ** Notice them** Add an ` onwarn ` function to the options, or listen
76
- to the ` 'warn' ` event on any tar stream. The function will get
77
- called as ` onwarn(message, data) ` . Handle as appropriate.
78
- 3 . ** Explode them.** Set ` strict: true ` in the options object, and
79
- ` warn ` messages will be emitted as ` 'error' ` events instead. If
80
- there's no ` error ` handler, this causes the program to crash. If
81
- used with a promise-returning/callback-taking method, then it'll
82
- send the error to the promise/callback.
66
+ ### Warnings and Errors
67
+
68
+ Tar emits warnings and errors for recoverable and unrecoverable situations,
69
+ respectively. In many cases, a warning only affects a single entry in an
70
+ archive, or is simply informing you that it's modifying an entry to comply
71
+ with the settings provided.
72
+
73
+ Unrecoverable warnings will always raise an error (ie, emit ` 'error' ` on
74
+ streaming actions, throw for non-streaming sync actions, reject the
75
+ returned Promise for non-streaming async operations, or call a provided
76
+ callback with an ` Error ` as the first argument). Recoverable errors will
77
+ raise an error only if ` strict: true ` is set in the options.
78
+
79
+ Respond to (recoverable) warnings by listening to the ` warn ` event.
80
+ Handlers receive 3 arguments:
81
+
82
+ - ` code ` String. One of the error codes below. This may not match
83
+ ` data.code ` , which preserves the original error code from fs and zlib.
84
+ - ` message ` String. More details about the error.
85
+ - ` data ` Metadata about the error. An ` Error ` object for errors raised by
86
+ fs and zlib. All fields are attached to errors raisd by tar. Typically
87
+ contains the following fields, as relevant:
88
+ - ` tarCode ` The tar error code.
89
+ - ` code ` Either the tar error code, or the error code set by the
90
+ underlying system.
91
+ - ` file ` The archive file being read or written.
92
+ - ` cwd ` Working directory for creation and extraction operations.
93
+ - ` entry ` The entry object (if it could be created) for ` TAR_ENTRY_INFO ` ,
94
+ ` TAR_ENTRY_INVALID ` , and ` TAR_ENTRY_ERROR ` warnings.
95
+ - ` header ` The header object (if it could be created, and the entry could
96
+ not be created) for ` TAR_ENTRY_INFO ` and ` TAR_ENTRY_INVALID ` warnings.
97
+ - ` recoverable ` Boolean. If ` false ` , then the warning will emit an
98
+ ` error ` , even in non-strict mode.
99
+
100
+ #### Error Codes
101
+
102
+ * ` TAR_ENTRY_INFO ` An informative error indicating that an entry is being
103
+ modified, but otherwise processed normally. For example, removing ` / ` or
104
+ ` C:\ ` from absolute paths if ` preservePaths ` is not set.
105
+
106
+ * ` TAR_ENTRY_INVALID ` An indication that a given entry is not a valid tar
107
+ archive entry, and will be skipped. This occurs when:
108
+ - a checksum fails,
109
+ - a ` linkpath ` is missing for a link type, or
110
+ - a ` linkpath ` is provided for a non-link type.
111
+
112
+ If every entry in a parsed archive raises an ` TAR_ENTRY_INVALID ` error,
113
+ then the archive is presumed to be unrecoverably broken, and
114
+ ` TAR_BAD_ARCHIVE ` will be raised.
115
+
116
+ * ` TAR_ENTRY_ERROR ` The entry appears to be a valid tar archive entry, but
117
+ encountered an error which prevented it from being unpacked. This occurs
118
+ when:
119
+ - an unrecoverable fs error happens during unpacking,
120
+ - an entry has ` .. ` in the path and ` preservePaths ` is not set, or
121
+ - an entry is extracting through a symbolic link, when ` preservePaths ` is
122
+ not set.
123
+
124
+ * ` TAR_ENTRY_UNSUPPORTED ` An indication that a given entry is
125
+ a valid archive entry, but of a type that is unsupported, and so will be
126
+ skipped in archive creation or extracting.
127
+
128
+ * ` TAR_ABORT ` When parsing gzipped-encoded archives, the parser will
129
+ abort the parse process raise a warning for any zlib errors encountered.
130
+ Aborts are considered unrecoverable for both parsing and unpacking.
131
+
132
+ * ` TAR_BAD_ARCHIVE ` The archive file is totally hosed. This can happen for
133
+ a number of reasons, and always occurs at the end of a parse or extract:
134
+
135
+ - An entry body was truncated before seeing the full number of bytes.
136
+ - The archive contained only invalid entries, indicating that it is
137
+ likely not an archive, or at least, not an archive this library can
138
+ parse.
139
+
140
+ ` TAR_BAD_ARCHIVE ` is considered informative for parse operations, but
141
+ unrecoverable for extraction. Note that, if encountered at the end of an
142
+ extraction, tar WILL still have extracted as much it could from the
143
+ archive, so there may be some garbage files to clean up.
144
+
145
+ Errors that occur deeper in the system (ie, either the filesystem or zlib)
146
+ will have their error codes left intact, and a ` tarCode ` matching one of
147
+ the above will be added to the warning metadata or the raised error object.
148
+
149
+ Errors generated by tar will have one of the above codes set as the
150
+ ` error.code ` field as well, but since errors originating in zlib or fs will
151
+ have their original codes, it's better to read ` error.tarCode ` if you wish
152
+ to see how tar is handling the issue.
83
153
84
154
### Examples
85
155
@@ -201,8 +271,8 @@ The following options are supported:
201
271
and a file is not provided, then the resulting stream will already
202
272
have the data ready to ` read ` or ` emit('data') ` as soon as you
203
273
request it.
204
- - ` onwarn ` A function that will get called with ` (message, data) ` for
205
- any warnings encountered.
274
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
275
+ any warnings encountered. (See "Warnings and Errors")
206
276
- ` strict ` Treat warnings as crash-worthy errors. Default false.
207
277
- ` cwd ` The current working directory for creating the archive.
208
278
Defaults to ` process.cwd() ` . [ Alias: ` C ` ]
@@ -297,8 +367,8 @@ The following options are supported:
297
367
Pathnames with fewer elements will be silently skipped. Note that
298
368
the pathname is edited after applying the filter, but before
299
369
security checks. [ Alias: ` strip-components ` , ` stripComponents ` ]
300
- - ` onwarn ` A function that will get called with ` (message, data) ` for
301
- any warnings encountered.
370
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
371
+ any warnings encountered. (See "Warnings and Errors")
302
372
- ` preserveOwner ` If true, tar will set the ` uid ` and ` gid ` of
303
373
extracted entries to the ` uid ` and ` gid ` fields in the archive.
304
374
This defaults to true when run as root, and false otherwise. If
@@ -401,8 +471,8 @@ The following options are supported:
401
471
filename. [ Alias: ` f ` ]
402
472
- ` sync ` Act synchronously. If this is set, then any provided file
403
473
will be fully written after the call to ` tar.c ` .
404
- - ` onwarn ` A function that will get called with ` (message, data) ` for
405
- any warnings encountered.
474
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
475
+ any warnings encountered. (See "Warnings and Errors")
406
476
- ` strict ` Treat warnings as crash-worthy errors. Default false.
407
477
- ` cwd ` The current working directory for adding entries to the
408
478
archive. Defaults to ` process.cwd() ` . [ Alias: ` C ` ]
@@ -452,8 +522,8 @@ The following options are supported:
452
522
filename. [ Alias: ` f ` ]
453
523
- ` sync ` Act synchronously. If this is set, then any provided file
454
524
will be fully written after the call to ` tar.c ` .
455
- - ` onwarn ` A function that will get called with ` (message, data) ` for
456
- any warnings encountered.
525
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
526
+ any warnings encountered. (See "Warnings and Errors")
457
527
- ` strict ` Treat warnings as crash-worthy errors. Default false.
458
528
- ` cwd ` The current working directory for adding entries to the
459
529
archive. Defaults to ` process.cwd() ` . [ Alias: ` C ` ]
@@ -499,8 +569,8 @@ Has all the standard readable stream interface stuff. `'data'` and
499
569
500
570
The following options are supported:
501
571
502
- - ` onwarn ` A function that will get called with ` (message, data) ` for
503
- any warnings encountered.
572
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
573
+ any warnings encountered. (See "Warnings and Errors")
504
574
- ` strict ` Treat warnings as crash-worthy errors. Default false.
505
575
- ` cwd ` The current working directory for creating the archive.
506
576
Defaults to ` process.cwd() ` .
@@ -595,8 +665,8 @@ Most unpack errors will cause a `warn` event to be emitted. If the
595
665
Pathnames with fewer elements will be silently skipped. Note that
596
666
the pathname is edited after applying the filter, but before
597
667
security checks.
598
- - ` onwarn ` A function that will get called with ` (message, data) ` for
599
- any warnings encountered.
668
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
669
+ any warnings encountered. (See "Warnings and Errors")
600
670
- ` umask ` Filter the modes of entries like ` process.umask() ` .
601
671
- ` dmode ` Default mode for directories
602
672
- ` fmode ` Default mode for files
@@ -634,8 +704,8 @@ Most unpack errors will cause a `warn` event to be emitted. If the
634
704
- ` strict ` Treat warnings as crash-worthy errors. Default false.
635
705
- ` onentry ` A function that gets called with ` (entry) ` for each entry
636
706
that passes the filter.
637
- - ` onwarn ` A function that will get called with ` (message, data) ` for
638
- any warnings encountered.
707
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
708
+ any warnings encountered. (See "Warnings and Errors")
639
709
640
710
### class tar.Unpack.Sync
641
711
@@ -674,13 +744,13 @@ The following options are supported:
674
744
archive, or ` false ` to skip it.
675
745
- ` onentry ` A function that gets called with ` (entry) ` for each entry
676
746
that passes the filter.
677
- - ` onwarn ` A function that will get called with ` (message, data) ` for
678
- any warnings encountered.
747
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
748
+ any warnings encountered. (See "Warnings and Errors")
679
749
680
- #### abort(message, error)
750
+ #### abort(error)
681
751
682
752
Stop all parsing activities. This is called when there are zlib
683
- errors. It also emits a warning with the message and error provided.
753
+ errors. It also emits an unrecoverable warning with the error provided.
684
754
685
755
### class tar.ReadEntry extends [ MiniPass] ( http://npm.im/minipass )
686
756
@@ -781,8 +851,8 @@ The following options are supported:
781
851
- ` strict ` Treat warnings as crash-worthy errors. Default false.
782
852
- ` win32 ` True if on a windows platform. Causes behavior where paths
783
853
replace ` \ ` with ` / ` .
784
- - ` onwarn ` A function that will get called with ` (message, data) ` for
785
- any warnings encountered.
854
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
855
+ any warnings encountered. (See "Warnings and Errors")
786
856
- ` noMtime ` Set to true to omit writing ` mtime ` values for entries.
787
857
Note that this prevents using other mtime-based features like
788
858
` tar.update ` or the ` keepNewer ` option with the resulting tar archive.
@@ -818,8 +888,8 @@ The following options are supported:
818
888
- ` preservePaths ` Allow absolute paths. By default, ` / ` is stripped
819
889
from absolute paths.
820
890
- ` strict ` Treat warnings as crash-worthy errors. Default false.
821
- - ` onwarn ` A function that will get called with ` (message, data) ` for
822
- any warnings encountered.
891
+ - ` onwarn ` A function that will get called with ` (code, message, data) ` for
892
+ any warnings encountered. (See "Warnings and Errors")
823
893
- ` noMtime ` Set to true to omit writing ` mtime ` values for entries.
824
894
Note that this prevents using other mtime-based features like
825
895
` tar.update ` or the ` keepNewer ` option with the resulting tar archive.
0 commit comments