@preventive/archive 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preventive/archive",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "Strict in-memory tar and zip on browser APIs",
5
5
  "type": "module",
6
6
  "exports": {
package/src/tar/unpack.js CHANGED
@@ -78,13 +78,16 @@ class Unpacker {
78
78
  #done = false
79
79
  #count = 0
80
80
  #maxEntries
81
+ #trailingGlobal
81
82
 
82
83
  // `keep` holds entries for a repeat to be compared with, which only the
83
84
  // in-memory call can afford; the options are unpack's.
84
- constructor(keep, { symlinksAbove, maxEntries = Infinity } = {}) {
85
+ constructor(keep, { symlinksAbove, maxEntries = Infinity, trailingGlobal = false } = {}) {
85
86
  if (maxEntries !== Infinity && !(Number.isSafeInteger(maxEntries) && maxEntries >= 0)) throw new ArchiveError(`maxEntries ${String(maxEntries)} is not a whole number of entries`)
87
+ if (typeof trailingGlobal !== 'boolean') throw new ArchiveError(`trailingGlobal ${String(trailingGlobal)} is not a boolean`)
86
88
  this.#names = new Names(keep, levelsAbove(symlinksAbove))
87
89
  this.#maxEntries = maxEntries
90
+ this.#trailingGlobal = trailingGlobal
88
91
  }
89
92
 
90
93
  // The entries a chunk completes, each as it is read, so that a chunk
@@ -155,8 +158,10 @@ class Unpacker {
155
158
  if (block === null) return false
156
159
  const at = this.#position - BLOCK
157
160
  if (isZeroBlock(block)) {
158
- // A global header too: one with no entry after it stands for nothing.
159
- if (this.#extended.length > 0) throw new ArchiveError('an extended header is not followed by an entry', at)
161
+ // A global header too: one with no entry after it stands for nothing,
162
+ // unless the caller takes it as GNU tar does (trailingGlobal).
163
+ const unused = this.#trailingGlobal ? this.#extended.filter(({ kind }) => kind !== 'global') : this.#extended
164
+ if (unused.length > 0) throw new ArchiveError('an extended header is not followed by an entry', at)
160
165
  if (++this.#zeros === 2) {
161
166
  this.#done = true
162
167
  const after = this.#position
package/tar.d.ts CHANGED
@@ -36,15 +36,16 @@ export type EntryType =
36
36
  // `extended` is the extended headers read since the entry before it, in
37
37
  // the order stored, each its kind -- its own pax header, a global one,
38
38
  // GNU's long name and long link -- and its magic; the one empty list where
39
- // none was, and frozen, as a Map is. An extended header, a global one too,
40
- // with no entry after it is refused. `magic` is the entry's own header's:
41
- // POSIX's 'ustar', or 'gnu', under which the bytes ustar holds a name's
42
- // prefix in are GNU's own and not read as one. `typeflag` and `storedMode`
43
- // are its header's type flag and mode as stored: '\0' where `type` is a
44
- // 'file' as '0' is, and the file type bits among the permission bits
45
- // `mode` keeps. `octal` is whether every numeric field of its header -- an
46
- // extended one's too -- holds octal digits, as POSIX writes them, rather
47
- // than nothing or GNU's base 256, both of which are read too.
39
+ // none was, and frozen, as a Map is. An extended header with no entry after
40
+ // it is refused, a global one too unless `trailingGlobal` takes it. `magic`
41
+ // is the entry's own header's: POSIX's 'ustar', or 'gnu', under which the
42
+ // bytes ustar holds a name's prefix in are GNU's own and not read as one.
43
+ // `typeflag` and `storedMode` are its header's type flag and mode as
44
+ // stored: '\0' where `type` is a 'file' as '0' is, and the file type bits
45
+ // among the permission bits `mode` keeps. `octal` is whether every numeric
46
+ // field of its header -- an extended one's too -- holds octal digits, as
47
+ // POSIX writes them, rather than nothing or GNU's base 256, both of which
48
+ // are read too.
48
49
  export interface Entry {
49
50
  name: string
50
51
  type: EntryType
@@ -125,8 +126,13 @@ export interface PackOptions extends SymlinkOptions {
125
126
  // counted and a repeat again, its extended headers not: past it the call
126
127
  // throws with `limited` set, at the header that crosses it, before that
127
128
  // entry is read. No bound by default.
129
+ // `trailingGlobal` takes a global header with no entry after it, as GNU tar
130
+ // lists one: as nothing, carried in no entry's `extended`. By default it is
131
+ // refused, as any extended header with no entry to describe is. A pax or
132
+ // long name header with nothing after it is refused either way.
128
133
  export interface UnpackOptions extends SymlinkOptions {
129
134
  maxEntries?: number
135
+ trailingGlobal?: boolean
130
136
  }
131
137
 
132
138
  // Both refuse a name that repeats as a different entry -- anything but the