tar 6.2.1 → 7.0.1

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.
Files changed (253) hide show
  1. package/README.md +30 -16
  2. package/dist/commonjs/create.d.ts +8 -0
  3. package/dist/commonjs/create.d.ts.map +1 -0
  4. package/dist/commonjs/create.js +106 -0
  5. package/dist/commonjs/create.js.map +1 -0
  6. package/dist/commonjs/cwd-error.d.ts +8 -0
  7. package/dist/commonjs/cwd-error.d.ts.map +1 -0
  8. package/dist/commonjs/cwd-error.js +18 -0
  9. package/dist/commonjs/cwd-error.js.map +1 -0
  10. package/dist/commonjs/extract.d.ts +8 -0
  11. package/dist/commonjs/extract.d.ts.map +1 -0
  12. package/dist/commonjs/extract.js +141 -0
  13. package/dist/commonjs/extract.js.map +1 -0
  14. package/dist/commonjs/get-write-flag.d.ts +2 -0
  15. package/dist/commonjs/get-write-flag.d.ts.map +1 -0
  16. package/dist/commonjs/get-write-flag.js +29 -0
  17. package/dist/commonjs/get-write-flag.js.map +1 -0
  18. package/dist/commonjs/header.d.ts +54 -0
  19. package/dist/commonjs/header.d.ts.map +1 -0
  20. package/dist/commonjs/header.js +311 -0
  21. package/dist/commonjs/header.js.map +1 -0
  22. package/dist/commonjs/index.d.ts +19 -0
  23. package/dist/commonjs/index.d.ts.map +1 -0
  24. package/dist/commonjs/index.js +54 -0
  25. package/dist/commonjs/index.js.map +1 -0
  26. package/dist/commonjs/large-numbers.d.ts +4 -0
  27. package/dist/commonjs/large-numbers.d.ts.map +1 -0
  28. package/dist/commonjs/large-numbers.js +99 -0
  29. package/dist/commonjs/large-numbers.js.map +1 -0
  30. package/dist/commonjs/list.d.ts +8 -0
  31. package/dist/commonjs/list.d.ts.map +1 -0
  32. package/dist/commonjs/list.js +167 -0
  33. package/dist/commonjs/list.js.map +1 -0
  34. package/dist/commonjs/mkdir.d.ts +27 -0
  35. package/dist/commonjs/mkdir.d.ts.map +1 -0
  36. package/dist/commonjs/mkdir.js +209 -0
  37. package/dist/commonjs/mkdir.js.map +1 -0
  38. package/dist/commonjs/mode-fix.d.ts +2 -0
  39. package/dist/commonjs/mode-fix.d.ts.map +1 -0
  40. package/dist/commonjs/mode-fix.js +29 -0
  41. package/dist/commonjs/mode-fix.js.map +1 -0
  42. package/dist/commonjs/normalize-unicode.d.ts +2 -0
  43. package/dist/commonjs/normalize-unicode.d.ts.map +1 -0
  44. package/dist/commonjs/normalize-unicode.js +17 -0
  45. package/dist/commonjs/normalize-unicode.js.map +1 -0
  46. package/dist/commonjs/normalize-windows-path.d.ts +2 -0
  47. package/dist/commonjs/normalize-windows-path.d.ts.map +1 -0
  48. package/dist/commonjs/normalize-windows-path.js +12 -0
  49. package/dist/commonjs/normalize-windows-path.js.map +1 -0
  50. package/dist/commonjs/options.d.ts +545 -0
  51. package/dist/commonjs/options.d.ts.map +1 -0
  52. package/dist/commonjs/options.js +55 -0
  53. package/dist/commonjs/options.js.map +1 -0
  54. package/dist/commonjs/pack.d.ts +98 -0
  55. package/dist/commonjs/pack.d.ts.map +1 -0
  56. package/dist/commonjs/pack.js +461 -0
  57. package/dist/commonjs/pack.js.map +1 -0
  58. package/dist/commonjs/package.json +3 -0
  59. package/dist/commonjs/parse.d.ts +84 -0
  60. package/dist/commonjs/parse.d.ts.map +1 -0
  61. package/dist/commonjs/parse.js +571 -0
  62. package/dist/commonjs/parse.js.map +1 -0
  63. package/dist/commonjs/path-reservations.d.ts +11 -0
  64. package/dist/commonjs/path-reservations.d.ts.map +1 -0
  65. package/dist/commonjs/path-reservations.js +169 -0
  66. package/dist/commonjs/path-reservations.js.map +1 -0
  67. package/dist/commonjs/pax.d.ts +27 -0
  68. package/dist/commonjs/pax.d.ts.map +1 -0
  69. package/dist/commonjs/pax.js +158 -0
  70. package/dist/commonjs/pax.js.map +1 -0
  71. package/dist/commonjs/read-entry.d.ts +37 -0
  72. package/dist/commonjs/read-entry.d.ts.map +1 -0
  73. package/dist/commonjs/read-entry.js +139 -0
  74. package/dist/commonjs/read-entry.js.map +1 -0
  75. package/dist/commonjs/replace.d.ts +5 -0
  76. package/dist/commonjs/replace.d.ts.map +1 -0
  77. package/dist/commonjs/replace.js +223 -0
  78. package/dist/commonjs/replace.js.map +1 -0
  79. package/dist/commonjs/strip-absolute-path.d.ts +2 -0
  80. package/dist/commonjs/strip-absolute-path.d.ts.map +1 -0
  81. package/dist/commonjs/strip-absolute-path.js +29 -0
  82. package/dist/commonjs/strip-absolute-path.js.map +1 -0
  83. package/dist/commonjs/strip-trailing-slashes.d.ts +2 -0
  84. package/dist/commonjs/strip-trailing-slashes.d.ts.map +1 -0
  85. package/dist/commonjs/strip-trailing-slashes.js +18 -0
  86. package/dist/commonjs/strip-trailing-slashes.js.map +1 -0
  87. package/dist/commonjs/symlink-error.d.ts +9 -0
  88. package/dist/commonjs/symlink-error.d.ts.map +1 -0
  89. package/dist/commonjs/symlink-error.js +19 -0
  90. package/dist/commonjs/symlink-error.js.map +1 -0
  91. package/dist/commonjs/types.d.ts +7 -0
  92. package/dist/commonjs/types.d.ts.map +1 -0
  93. package/dist/commonjs/types.js +50 -0
  94. package/dist/commonjs/types.js.map +1 -0
  95. package/dist/commonjs/unpack.d.ts +98 -0
  96. package/dist/commonjs/unpack.d.ts.map +1 -0
  97. package/dist/commonjs/unpack.js +921 -0
  98. package/dist/commonjs/unpack.js.map +1 -0
  99. package/dist/commonjs/update.d.ts +3 -0
  100. package/dist/commonjs/update.d.ts.map +1 -0
  101. package/dist/commonjs/update.js +47 -0
  102. package/dist/commonjs/update.js.map +1 -0
  103. package/dist/commonjs/warn-method.d.ts +20 -0
  104. package/dist/commonjs/warn-method.d.ts.map +1 -0
  105. package/dist/commonjs/warn-method.js +31 -0
  106. package/dist/commonjs/warn-method.js.map +1 -0
  107. package/dist/commonjs/winchars.d.ts +3 -0
  108. package/dist/commonjs/winchars.d.ts.map +1 -0
  109. package/dist/commonjs/winchars.js +14 -0
  110. package/dist/commonjs/winchars.js.map +1 -0
  111. package/dist/commonjs/write-entry.d.ts +125 -0
  112. package/dist/commonjs/write-entry.d.ts.map +1 -0
  113. package/dist/commonjs/write-entry.js +657 -0
  114. package/dist/commonjs/write-entry.js.map +1 -0
  115. package/dist/esm/create.d.ts +8 -0
  116. package/dist/esm/create.d.ts.map +1 -0
  117. package/dist/esm/create.js +99 -0
  118. package/dist/esm/create.js.map +1 -0
  119. package/dist/esm/cwd-error.d.ts +8 -0
  120. package/dist/esm/cwd-error.d.ts.map +1 -0
  121. package/dist/esm/cwd-error.js +14 -0
  122. package/dist/esm/cwd-error.js.map +1 -0
  123. package/dist/esm/extract.d.ts +8 -0
  124. package/dist/esm/extract.d.ts.map +1 -0
  125. package/dist/esm/extract.js +111 -0
  126. package/dist/esm/extract.js.map +1 -0
  127. package/dist/esm/get-write-flag.d.ts +2 -0
  128. package/dist/esm/get-write-flag.d.ts.map +1 -0
  129. package/dist/esm/get-write-flag.js +23 -0
  130. package/dist/esm/get-write-flag.js.map +1 -0
  131. package/dist/esm/header.d.ts +54 -0
  132. package/dist/esm/header.d.ts.map +1 -0
  133. package/dist/esm/header.js +284 -0
  134. package/dist/esm/header.js.map +1 -0
  135. package/dist/esm/index.d.ts +19 -0
  136. package/dist/esm/index.d.ts.map +1 -0
  137. package/dist/esm/index.js +20 -0
  138. package/dist/esm/index.js.map +1 -0
  139. package/dist/esm/large-numbers.d.ts +4 -0
  140. package/dist/esm/large-numbers.d.ts.map +1 -0
  141. package/dist/esm/large-numbers.js +94 -0
  142. package/dist/esm/large-numbers.js.map +1 -0
  143. package/dist/esm/list.d.ts +8 -0
  144. package/dist/esm/list.d.ts.map +1 -0
  145. package/dist/esm/list.js +137 -0
  146. package/dist/esm/list.js.map +1 -0
  147. package/dist/esm/mkdir.d.ts +27 -0
  148. package/dist/esm/mkdir.d.ts.map +1 -0
  149. package/dist/esm/mkdir.js +201 -0
  150. package/dist/esm/mkdir.js.map +1 -0
  151. package/dist/esm/mode-fix.d.ts +2 -0
  152. package/dist/esm/mode-fix.d.ts.map +1 -0
  153. package/dist/esm/mode-fix.js +25 -0
  154. package/dist/esm/mode-fix.js.map +1 -0
  155. package/dist/esm/normalize-unicode.d.ts +2 -0
  156. package/dist/esm/normalize-unicode.d.ts.map +1 -0
  157. package/dist/esm/normalize-unicode.js +13 -0
  158. package/dist/esm/normalize-unicode.js.map +1 -0
  159. package/dist/esm/normalize-windows-path.d.ts +2 -0
  160. package/dist/esm/normalize-windows-path.d.ts.map +1 -0
  161. package/{lib → dist/esm}/normalize-windows-path.js +5 -4
  162. package/dist/esm/normalize-windows-path.js.map +1 -0
  163. package/dist/esm/options.d.ts +545 -0
  164. package/dist/esm/options.d.ts.map +1 -0
  165. package/dist/esm/options.js +48 -0
  166. package/dist/esm/options.js.map +1 -0
  167. package/dist/esm/pack.d.ts +98 -0
  168. package/dist/esm/pack.d.ts.map +1 -0
  169. package/dist/esm/pack.js +429 -0
  170. package/dist/esm/pack.js.map +1 -0
  171. package/dist/esm/package.json +3 -0
  172. package/dist/esm/parse.d.ts +84 -0
  173. package/dist/esm/parse.d.ts.map +1 -0
  174. package/dist/esm/parse.js +567 -0
  175. package/dist/esm/parse.js.map +1 -0
  176. package/dist/esm/path-reservations.d.ts +11 -0
  177. package/dist/esm/path-reservations.d.ts.map +1 -0
  178. package/dist/esm/path-reservations.js +165 -0
  179. package/dist/esm/path-reservations.js.map +1 -0
  180. package/dist/esm/pax.d.ts +27 -0
  181. package/dist/esm/pax.d.ts.map +1 -0
  182. package/dist/esm/pax.js +154 -0
  183. package/dist/esm/pax.js.map +1 -0
  184. package/dist/esm/read-entry.d.ts +37 -0
  185. package/dist/esm/read-entry.d.ts.map +1 -0
  186. package/dist/esm/read-entry.js +135 -0
  187. package/dist/esm/read-entry.js.map +1 -0
  188. package/dist/esm/replace.d.ts +5 -0
  189. package/dist/esm/replace.d.ts.map +1 -0
  190. package/dist/esm/replace.js +216 -0
  191. package/dist/esm/replace.js.map +1 -0
  192. package/dist/esm/strip-absolute-path.d.ts +2 -0
  193. package/dist/esm/strip-absolute-path.d.ts.map +1 -0
  194. package/dist/esm/strip-absolute-path.js +25 -0
  195. package/dist/esm/strip-absolute-path.js.map +1 -0
  196. package/dist/esm/strip-trailing-slashes.d.ts +2 -0
  197. package/dist/esm/strip-trailing-slashes.d.ts.map +1 -0
  198. package/dist/esm/strip-trailing-slashes.js +14 -0
  199. package/dist/esm/strip-trailing-slashes.js.map +1 -0
  200. package/dist/esm/symlink-error.d.ts +9 -0
  201. package/dist/esm/symlink-error.d.ts.map +1 -0
  202. package/dist/esm/symlink-error.js +15 -0
  203. package/dist/esm/symlink-error.js.map +1 -0
  204. package/dist/esm/types.d.ts +7 -0
  205. package/dist/esm/types.d.ts.map +1 -0
  206. package/dist/esm/types.js +45 -0
  207. package/dist/esm/types.js.map +1 -0
  208. package/dist/esm/unpack.d.ts +98 -0
  209. package/dist/esm/unpack.d.ts.map +1 -0
  210. package/dist/esm/unpack.js +890 -0
  211. package/dist/esm/unpack.js.map +1 -0
  212. package/dist/esm/update.d.ts +3 -0
  213. package/dist/esm/update.d.ts.map +1 -0
  214. package/dist/esm/update.js +43 -0
  215. package/dist/esm/update.js.map +1 -0
  216. package/dist/esm/warn-method.d.ts +20 -0
  217. package/dist/esm/warn-method.d.ts.map +1 -0
  218. package/dist/esm/warn-method.js +27 -0
  219. package/dist/esm/warn-method.js.map +1 -0
  220. package/dist/esm/winchars.d.ts +3 -0
  221. package/dist/esm/winchars.d.ts.map +1 -0
  222. package/dist/esm/winchars.js +9 -0
  223. package/dist/esm/winchars.js.map +1 -0
  224. package/dist/esm/write-entry.d.ts +125 -0
  225. package/dist/esm/write-entry.d.ts.map +1 -0
  226. package/dist/esm/write-entry.js +625 -0
  227. package/dist/esm/write-entry.js.map +1 -0
  228. package/package.json +255 -40
  229. package/index.js +0 -18
  230. package/lib/create.js +0 -111
  231. package/lib/extract.js +0 -113
  232. package/lib/get-write-flag.js +0 -20
  233. package/lib/header.js +0 -304
  234. package/lib/high-level-opt.js +0 -29
  235. package/lib/large-numbers.js +0 -104
  236. package/lib/list.js +0 -139
  237. package/lib/mkdir.js +0 -229
  238. package/lib/mode-fix.js +0 -27
  239. package/lib/normalize-unicode.js +0 -12
  240. package/lib/pack.js +0 -432
  241. package/lib/parse.js +0 -552
  242. package/lib/path-reservations.js +0 -156
  243. package/lib/pax.js +0 -150
  244. package/lib/read-entry.js +0 -107
  245. package/lib/replace.js +0 -246
  246. package/lib/strip-absolute-path.js +0 -24
  247. package/lib/strip-trailing-slashes.js +0 -13
  248. package/lib/types.js +0 -44
  249. package/lib/unpack.js +0 -923
  250. package/lib/update.js +0 -40
  251. package/lib/warn-mixin.js +0 -24
  252. package/lib/winchars.js +0 -23
  253. package/lib/write-entry.js +0 -546
@@ -1,20 +0,0 @@
1
- // Get the appropriate flag to use for creating files
2
- // We use fmap on Windows platforms for files less than
3
- // 512kb. This is a fairly low limit, but avoids making
4
- // things slower in some cases. Since most of what this
5
- // library is used for is extracting tarballs of many
6
- // relatively small files in npm packages and the like,
7
- // it can be a big boost on Windows platforms.
8
- // Only supported in Node v12.9.0 and above.
9
- const platform = process.env.__FAKE_PLATFORM__ || process.platform
10
- const isWindows = platform === 'win32'
11
- const fs = global.__FAKE_TESTING_FS__ || require('fs')
12
-
13
- /* istanbul ignore next */
14
- const { O_CREAT, O_TRUNC, O_WRONLY, UV_FS_O_FILEMAP = 0 } = fs.constants
15
-
16
- const fMapEnabled = isWindows && !!UV_FS_O_FILEMAP
17
- const fMapLimit = 512 * 1024
18
- const fMapFlag = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY
19
- module.exports = !fMapEnabled ? () => 'w'
20
- : size => size < fMapLimit ? fMapFlag : 'w'
package/lib/header.js DELETED
@@ -1,304 +0,0 @@
1
- 'use strict'
2
- // parse a 512-byte header block to a data object, or vice-versa
3
- // encode returns `true` if a pax extended header is needed, because
4
- // the data could not be faithfully encoded in a simple header.
5
- // (Also, check header.needPax to see if it needs a pax header.)
6
-
7
- const types = require('./types.js')
8
- const pathModule = require('path').posix
9
- const large = require('./large-numbers.js')
10
-
11
- const SLURP = Symbol('slurp')
12
- const TYPE = Symbol('type')
13
-
14
- class Header {
15
- constructor (data, off, ex, gex) {
16
- this.cksumValid = false
17
- this.needPax = false
18
- this.nullBlock = false
19
-
20
- this.block = null
21
- this.path = null
22
- this.mode = null
23
- this.uid = null
24
- this.gid = null
25
- this.size = null
26
- this.mtime = null
27
- this.cksum = null
28
- this[TYPE] = '0'
29
- this.linkpath = null
30
- this.uname = null
31
- this.gname = null
32
- this.devmaj = 0
33
- this.devmin = 0
34
- this.atime = null
35
- this.ctime = null
36
-
37
- if (Buffer.isBuffer(data)) {
38
- this.decode(data, off || 0, ex, gex)
39
- } else if (data) {
40
- this.set(data)
41
- }
42
- }
43
-
44
- decode (buf, off, ex, gex) {
45
- if (!off) {
46
- off = 0
47
- }
48
-
49
- if (!buf || !(buf.length >= off + 512)) {
50
- throw new Error('need 512 bytes for header')
51
- }
52
-
53
- this.path = decString(buf, off, 100)
54
- this.mode = decNumber(buf, off + 100, 8)
55
- this.uid = decNumber(buf, off + 108, 8)
56
- this.gid = decNumber(buf, off + 116, 8)
57
- this.size = decNumber(buf, off + 124, 12)
58
- this.mtime = decDate(buf, off + 136, 12)
59
- this.cksum = decNumber(buf, off + 148, 12)
60
-
61
- // if we have extended or global extended headers, apply them now
62
- // See https://github.com/npm/node-tar/pull/187
63
- this[SLURP](ex)
64
- this[SLURP](gex, true)
65
-
66
- // old tar versions marked dirs as a file with a trailing /
67
- this[TYPE] = decString(buf, off + 156, 1)
68
- if (this[TYPE] === '') {
69
- this[TYPE] = '0'
70
- }
71
- if (this[TYPE] === '0' && this.path.slice(-1) === '/') {
72
- this[TYPE] = '5'
73
- }
74
-
75
- // tar implementations sometimes incorrectly put the stat(dir).size
76
- // as the size in the tarball, even though Directory entries are
77
- // not able to have any body at all. In the very rare chance that
78
- // it actually DOES have a body, we weren't going to do anything with
79
- // it anyway, and it'll just be a warning about an invalid header.
80
- if (this[TYPE] === '5') {
81
- this.size = 0
82
- }
83
-
84
- this.linkpath = decString(buf, off + 157, 100)
85
- if (buf.slice(off + 257, off + 265).toString() === 'ustar\u000000') {
86
- this.uname = decString(buf, off + 265, 32)
87
- this.gname = decString(buf, off + 297, 32)
88
- this.devmaj = decNumber(buf, off + 329, 8)
89
- this.devmin = decNumber(buf, off + 337, 8)
90
- if (buf[off + 475] !== 0) {
91
- // definitely a prefix, definitely >130 chars.
92
- const prefix = decString(buf, off + 345, 155)
93
- this.path = prefix + '/' + this.path
94
- } else {
95
- const prefix = decString(buf, off + 345, 130)
96
- if (prefix) {
97
- this.path = prefix + '/' + this.path
98
- }
99
- this.atime = decDate(buf, off + 476, 12)
100
- this.ctime = decDate(buf, off + 488, 12)
101
- }
102
- }
103
-
104
- let sum = 8 * 0x20
105
- for (let i = off; i < off + 148; i++) {
106
- sum += buf[i]
107
- }
108
-
109
- for (let i = off + 156; i < off + 512; i++) {
110
- sum += buf[i]
111
- }
112
-
113
- this.cksumValid = sum === this.cksum
114
- if (this.cksum === null && sum === 8 * 0x20) {
115
- this.nullBlock = true
116
- }
117
- }
118
-
119
- [SLURP] (ex, global) {
120
- for (const k in ex) {
121
- // we slurp in everything except for the path attribute in
122
- // a global extended header, because that's weird.
123
- if (ex[k] !== null && ex[k] !== undefined &&
124
- !(global && k === 'path')) {
125
- this[k] = ex[k]
126
- }
127
- }
128
- }
129
-
130
- encode (buf, off) {
131
- if (!buf) {
132
- buf = this.block = Buffer.alloc(512)
133
- off = 0
134
- }
135
-
136
- if (!off) {
137
- off = 0
138
- }
139
-
140
- if (!(buf.length >= off + 512)) {
141
- throw new Error('need 512 bytes for header')
142
- }
143
-
144
- const prefixSize = this.ctime || this.atime ? 130 : 155
145
- const split = splitPrefix(this.path || '', prefixSize)
146
- const path = split[0]
147
- const prefix = split[1]
148
- this.needPax = split[2]
149
-
150
- this.needPax = encString(buf, off, 100, path) || this.needPax
151
- this.needPax = encNumber(buf, off + 100, 8, this.mode) || this.needPax
152
- this.needPax = encNumber(buf, off + 108, 8, this.uid) || this.needPax
153
- this.needPax = encNumber(buf, off + 116, 8, this.gid) || this.needPax
154
- this.needPax = encNumber(buf, off + 124, 12, this.size) || this.needPax
155
- this.needPax = encDate(buf, off + 136, 12, this.mtime) || this.needPax
156
- buf[off + 156] = this[TYPE].charCodeAt(0)
157
- this.needPax = encString(buf, off + 157, 100, this.linkpath) || this.needPax
158
- buf.write('ustar\u000000', off + 257, 8)
159
- this.needPax = encString(buf, off + 265, 32, this.uname) || this.needPax
160
- this.needPax = encString(buf, off + 297, 32, this.gname) || this.needPax
161
- this.needPax = encNumber(buf, off + 329, 8, this.devmaj) || this.needPax
162
- this.needPax = encNumber(buf, off + 337, 8, this.devmin) || this.needPax
163
- this.needPax = encString(buf, off + 345, prefixSize, prefix) || this.needPax
164
- if (buf[off + 475] !== 0) {
165
- this.needPax = encString(buf, off + 345, 155, prefix) || this.needPax
166
- } else {
167
- this.needPax = encString(buf, off + 345, 130, prefix) || this.needPax
168
- this.needPax = encDate(buf, off + 476, 12, this.atime) || this.needPax
169
- this.needPax = encDate(buf, off + 488, 12, this.ctime) || this.needPax
170
- }
171
-
172
- let sum = 8 * 0x20
173
- for (let i = off; i < off + 148; i++) {
174
- sum += buf[i]
175
- }
176
-
177
- for (let i = off + 156; i < off + 512; i++) {
178
- sum += buf[i]
179
- }
180
-
181
- this.cksum = sum
182
- encNumber(buf, off + 148, 8, this.cksum)
183
- this.cksumValid = true
184
-
185
- return this.needPax
186
- }
187
-
188
- set (data) {
189
- for (const i in data) {
190
- if (data[i] !== null && data[i] !== undefined) {
191
- this[i] = data[i]
192
- }
193
- }
194
- }
195
-
196
- get type () {
197
- return types.name.get(this[TYPE]) || this[TYPE]
198
- }
199
-
200
- get typeKey () {
201
- return this[TYPE]
202
- }
203
-
204
- set type (type) {
205
- if (types.code.has(type)) {
206
- this[TYPE] = types.code.get(type)
207
- } else {
208
- this[TYPE] = type
209
- }
210
- }
211
- }
212
-
213
- const splitPrefix = (p, prefixSize) => {
214
- const pathSize = 100
215
- let pp = p
216
- let prefix = ''
217
- let ret
218
- const root = pathModule.parse(p).root || '.'
219
-
220
- if (Buffer.byteLength(pp) < pathSize) {
221
- ret = [pp, prefix, false]
222
- } else {
223
- // first set prefix to the dir, and path to the base
224
- prefix = pathModule.dirname(pp)
225
- pp = pathModule.basename(pp)
226
-
227
- do {
228
- if (Buffer.byteLength(pp) <= pathSize &&
229
- Buffer.byteLength(prefix) <= prefixSize) {
230
- // both fit!
231
- ret = [pp, prefix, false]
232
- } else if (Buffer.byteLength(pp) > pathSize &&
233
- Buffer.byteLength(prefix) <= prefixSize) {
234
- // prefix fits in prefix, but path doesn't fit in path
235
- ret = [pp.slice(0, pathSize - 1), prefix, true]
236
- } else {
237
- // make path take a bit from prefix
238
- pp = pathModule.join(pathModule.basename(prefix), pp)
239
- prefix = pathModule.dirname(prefix)
240
- }
241
- } while (prefix !== root && !ret)
242
-
243
- // at this point, found no resolution, just truncate
244
- if (!ret) {
245
- ret = [p.slice(0, pathSize - 1), '', true]
246
- }
247
- }
248
- return ret
249
- }
250
-
251
- const decString = (buf, off, size) =>
252
- buf.slice(off, off + size).toString('utf8').replace(/\0.*/, '')
253
-
254
- const decDate = (buf, off, size) =>
255
- numToDate(decNumber(buf, off, size))
256
-
257
- const numToDate = num => num === null ? null : new Date(num * 1000)
258
-
259
- const decNumber = (buf, off, size) =>
260
- buf[off] & 0x80 ? large.parse(buf.slice(off, off + size))
261
- : decSmallNumber(buf, off, size)
262
-
263
- const nanNull = value => isNaN(value) ? null : value
264
-
265
- const decSmallNumber = (buf, off, size) =>
266
- nanNull(parseInt(
267
- buf.slice(off, off + size)
268
- .toString('utf8').replace(/\0.*$/, '').trim(), 8))
269
-
270
- // the maximum encodable as a null-terminated octal, by field size
271
- const MAXNUM = {
272
- 12: 0o77777777777,
273
- 8: 0o7777777,
274
- }
275
-
276
- const encNumber = (buf, off, size, number) =>
277
- number === null ? false :
278
- number > MAXNUM[size] || number < 0
279
- ? (large.encode(number, buf.slice(off, off + size)), true)
280
- : (encSmallNumber(buf, off, size, number), false)
281
-
282
- const encSmallNumber = (buf, off, size, number) =>
283
- buf.write(octalString(number, size), off, size, 'ascii')
284
-
285
- const octalString = (number, size) =>
286
- padOctal(Math.floor(number).toString(8), size)
287
-
288
- const padOctal = (string, size) =>
289
- (string.length === size - 1 ? string
290
- : new Array(size - string.length - 1).join('0') + string + ' ') + '\0'
291
-
292
- const encDate = (buf, off, size, date) =>
293
- date === null ? false :
294
- encNumber(buf, off, size, date.getTime() / 1000)
295
-
296
- // enough to fill the longest string we've got
297
- const NULLS = new Array(156).join('\0')
298
- // pad with nulls, return true if it's longer or non-ascii
299
- const encString = (buf, off, size, string) =>
300
- string === null ? false :
301
- (buf.write(string + NULLS, off, size, 'utf8'),
302
- string.length !== Buffer.byteLength(string) || string.length > size)
303
-
304
- module.exports = Header
@@ -1,29 +0,0 @@
1
- 'use strict'
2
-
3
- // turn tar(1) style args like `C` into the more verbose things like `cwd`
4
-
5
- const argmap = new Map([
6
- ['C', 'cwd'],
7
- ['f', 'file'],
8
- ['z', 'gzip'],
9
- ['P', 'preservePaths'],
10
- ['U', 'unlink'],
11
- ['strip-components', 'strip'],
12
- ['stripComponents', 'strip'],
13
- ['keep-newer', 'newer'],
14
- ['keepNewer', 'newer'],
15
- ['keep-newer-files', 'newer'],
16
- ['keepNewerFiles', 'newer'],
17
- ['k', 'keep'],
18
- ['keep-existing', 'keep'],
19
- ['keepExisting', 'keep'],
20
- ['m', 'noMtime'],
21
- ['no-mtime', 'noMtime'],
22
- ['p', 'preserveOwner'],
23
- ['L', 'follow'],
24
- ['h', 'follow'],
25
- ])
26
-
27
- module.exports = opt => opt ? Object.keys(opt).map(k => [
28
- argmap.has(k) ? argmap.get(k) : k, opt[k],
29
- ]).reduce((set, kv) => (set[kv[0]] = kv[1], set), Object.create(null)) : {}
@@ -1,104 +0,0 @@
1
- 'use strict'
2
- // Tar can encode large and negative numbers using a leading byte of
3
- // 0xff for negative, and 0x80 for positive.
4
-
5
- const encode = (num, buf) => {
6
- if (!Number.isSafeInteger(num)) {
7
- // The number is so large that javascript cannot represent it with integer
8
- // precision.
9
- throw Error('cannot encode number outside of javascript safe integer range')
10
- } else if (num < 0) {
11
- encodeNegative(num, buf)
12
- } else {
13
- encodePositive(num, buf)
14
- }
15
- return buf
16
- }
17
-
18
- const encodePositive = (num, buf) => {
19
- buf[0] = 0x80
20
-
21
- for (var i = buf.length; i > 1; i--) {
22
- buf[i - 1] = num & 0xff
23
- num = Math.floor(num / 0x100)
24
- }
25
- }
26
-
27
- const encodeNegative = (num, buf) => {
28
- buf[0] = 0xff
29
- var flipped = false
30
- num = num * -1
31
- for (var i = buf.length; i > 1; i--) {
32
- var byte = num & 0xff
33
- num = Math.floor(num / 0x100)
34
- if (flipped) {
35
- buf[i - 1] = onesComp(byte)
36
- } else if (byte === 0) {
37
- buf[i - 1] = 0
38
- } else {
39
- flipped = true
40
- buf[i - 1] = twosComp(byte)
41
- }
42
- }
43
- }
44
-
45
- const parse = (buf) => {
46
- const pre = buf[0]
47
- const value = pre === 0x80 ? pos(buf.slice(1, buf.length))
48
- : pre === 0xff ? twos(buf)
49
- : null
50
- if (value === null) {
51
- throw Error('invalid base256 encoding')
52
- }
53
-
54
- if (!Number.isSafeInteger(value)) {
55
- // The number is so large that javascript cannot represent it with integer
56
- // precision.
57
- throw Error('parsed number outside of javascript safe integer range')
58
- }
59
-
60
- return value
61
- }
62
-
63
- const twos = (buf) => {
64
- var len = buf.length
65
- var sum = 0
66
- var flipped = false
67
- for (var i = len - 1; i > -1; i--) {
68
- var byte = buf[i]
69
- var f
70
- if (flipped) {
71
- f = onesComp(byte)
72
- } else if (byte === 0) {
73
- f = byte
74
- } else {
75
- flipped = true
76
- f = twosComp(byte)
77
- }
78
- if (f !== 0) {
79
- sum -= f * Math.pow(256, len - i - 1)
80
- }
81
- }
82
- return sum
83
- }
84
-
85
- const pos = (buf) => {
86
- var len = buf.length
87
- var sum = 0
88
- for (var i = len - 1; i > -1; i--) {
89
- var byte = buf[i]
90
- if (byte !== 0) {
91
- sum += byte * Math.pow(256, len - i - 1)
92
- }
93
- }
94
- return sum
95
- }
96
-
97
- const onesComp = byte => (0xff ^ byte) & 0xff
98
-
99
- const twosComp = byte => ((0xff ^ byte) + 1) & 0xff
100
-
101
- module.exports = {
102
- encode,
103
- parse,
104
- }
package/lib/list.js DELETED
@@ -1,139 +0,0 @@
1
- 'use strict'
2
-
3
- // XXX: This shares a lot in common with extract.js
4
- // maybe some DRY opportunity here?
5
-
6
- // tar -t
7
- const hlo = require('./high-level-opt.js')
8
- const Parser = require('./parse.js')
9
- const fs = require('fs')
10
- const fsm = require('fs-minipass')
11
- const path = require('path')
12
- const stripSlash = require('./strip-trailing-slashes.js')
13
-
14
- module.exports = (opt_, files, cb) => {
15
- if (typeof opt_ === 'function') {
16
- cb = opt_, files = null, opt_ = {}
17
- } else if (Array.isArray(opt_)) {
18
- files = opt_, opt_ = {}
19
- }
20
-
21
- if (typeof files === 'function') {
22
- cb = files, files = null
23
- }
24
-
25
- if (!files) {
26
- files = []
27
- } else {
28
- files = Array.from(files)
29
- }
30
-
31
- const opt = hlo(opt_)
32
-
33
- if (opt.sync && typeof cb === 'function') {
34
- throw new TypeError('callback not supported for sync tar functions')
35
- }
36
-
37
- if (!opt.file && typeof cb === 'function') {
38
- throw new TypeError('callback only supported with file option')
39
- }
40
-
41
- if (files.length) {
42
- filesFilter(opt, files)
43
- }
44
-
45
- if (!opt.noResume) {
46
- onentryFunction(opt)
47
- }
48
-
49
- return opt.file && opt.sync ? listFileSync(opt)
50
- : opt.file ? listFile(opt, cb)
51
- : list(opt)
52
- }
53
-
54
- const onentryFunction = opt => {
55
- const onentry = opt.onentry
56
- opt.onentry = onentry ? e => {
57
- onentry(e)
58
- e.resume()
59
- } : e => e.resume()
60
- }
61
-
62
- // construct a filter that limits the file entries listed
63
- // include child entries if a dir is included
64
- const filesFilter = (opt, files) => {
65
- const map = new Map(files.map(f => [stripSlash(f), true]))
66
- const filter = opt.filter
67
-
68
- const mapHas = (file, r) => {
69
- const root = r || path.parse(file).root || '.'
70
- const ret = file === root ? false
71
- : map.has(file) ? map.get(file)
72
- : mapHas(path.dirname(file), root)
73
-
74
- map.set(file, ret)
75
- return ret
76
- }
77
-
78
- opt.filter = filter
79
- ? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
80
- : file => mapHas(stripSlash(file))
81
- }
82
-
83
- const listFileSync = opt => {
84
- const p = list(opt)
85
- const file = opt.file
86
- let threw = true
87
- let fd
88
- try {
89
- const stat = fs.statSync(file)
90
- const readSize = opt.maxReadSize || 16 * 1024 * 1024
91
- if (stat.size < readSize) {
92
- p.end(fs.readFileSync(file))
93
- } else {
94
- let pos = 0
95
- const buf = Buffer.allocUnsafe(readSize)
96
- fd = fs.openSync(file, 'r')
97
- while (pos < stat.size) {
98
- const bytesRead = fs.readSync(fd, buf, 0, readSize, pos)
99
- pos += bytesRead
100
- p.write(buf.slice(0, bytesRead))
101
- }
102
- p.end()
103
- }
104
- threw = false
105
- } finally {
106
- if (threw && fd) {
107
- try {
108
- fs.closeSync(fd)
109
- } catch (er) {}
110
- }
111
- }
112
- }
113
-
114
- const listFile = (opt, cb) => {
115
- const parse = new Parser(opt)
116
- const readSize = opt.maxReadSize || 16 * 1024 * 1024
117
-
118
- const file = opt.file
119
- const p = new Promise((resolve, reject) => {
120
- parse.on('error', reject)
121
- parse.on('end', resolve)
122
-
123
- fs.stat(file, (er, stat) => {
124
- if (er) {
125
- reject(er)
126
- } else {
127
- const stream = new fsm.ReadStream(file, {
128
- readSize: readSize,
129
- size: stat.size,
130
- })
131
- stream.on('error', reject)
132
- stream.pipe(parse)
133
- }
134
- })
135
- })
136
- return cb ? p.then(cb, cb) : p
137
- }
138
-
139
- const list = opt => new Parser(opt)