You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
723 lines
19 KiB
723 lines
19 KiB
|
3 years ago
|
<!doctype html>
|
||
|
|
<html lang="en">
|
||
|
|
<head>
|
||
|
|
<title>Code coverage report for tar/lib/replace.js</title>
|
||
|
|
<meta charset="utf-8" />
|
||
|
|
<link rel="stylesheet" href="../../prettify.css" />
|
||
|
|
<link rel="stylesheet" href="../../base.css" />
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
|
|
<style type='text/css'>
|
||
|
|
.coverage-summary .sorter {
|
||
|
|
background-image: url(../../sort-arrow-sprite.png);
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class='wrapper'>
|
||
|
|
<div class='pad1'>
|
||
|
|
<h1>
|
||
|
|
<a href="../../index.html">All files</a> / <a href="index.html">tar/lib</a> replace.js
|
||
|
|
</h1>
|
||
|
|
<div class='clearfix'>
|
||
|
|
<div class='fl pad1y space-right2'>
|
||
|
|
<span class="strong">100% </span>
|
||
|
|
<span class="quiet">Statements</span>
|
||
|
|
<span class='fraction'>131/131</span>
|
||
|
|
</div>
|
||
|
|
<div class='fl pad1y space-right2'>
|
||
|
|
<span class="strong">100% </span>
|
||
|
|
<span class="quiet">Branches</span>
|
||
|
|
<span class='fraction'>70/70</span>
|
||
|
|
</div>
|
||
|
|
<div class='fl pad1y space-right2'>
|
||
|
|
<span class="strong">100% </span>
|
||
|
|
<span class="quiet">Functions</span>
|
||
|
|
<span class='fraction'>18/18</span>
|
||
|
|
</div>
|
||
|
|
<div class='fl pad1y space-right2'>
|
||
|
|
<span class="strong">100% </span>
|
||
|
|
<span class="quiet">Lines</span>
|
||
|
|
<span class='fraction'>128/128</span>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class='status-line high'></div>
|
||
|
|
<pre><table class="coverage">
|
||
|
|
<tr><td class="line-count quiet">1
|
||
|
|
2
|
||
|
|
3
|
||
|
|
4
|
||
|
|
5
|
||
|
|
6
|
||
|
|
7
|
||
|
|
8
|
||
|
|
9
|
||
|
|
10
|
||
|
|
11
|
||
|
|
12
|
||
|
|
13
|
||
|
|
14
|
||
|
|
15
|
||
|
|
16
|
||
|
|
17
|
||
|
|
18
|
||
|
|
19
|
||
|
|
20
|
||
|
|
21
|
||
|
|
22
|
||
|
|
23
|
||
|
|
24
|
||
|
|
25
|
||
|
|
26
|
||
|
|
27
|
||
|
|
28
|
||
|
|
29
|
||
|
|
30
|
||
|
|
31
|
||
|
|
32
|
||
|
|
33
|
||
|
|
34
|
||
|
|
35
|
||
|
|
36
|
||
|
|
37
|
||
|
|
38
|
||
|
|
39
|
||
|
|
40
|
||
|
|
41
|
||
|
|
42
|
||
|
|
43
|
||
|
|
44
|
||
|
|
45
|
||
|
|
46
|
||
|
|
47
|
||
|
|
48
|
||
|
|
49
|
||
|
|
50
|
||
|
|
51
|
||
|
|
52
|
||
|
|
53
|
||
|
|
54
|
||
|
|
55
|
||
|
|
56
|
||
|
|
57
|
||
|
|
58
|
||
|
|
59
|
||
|
|
60
|
||
|
|
61
|
||
|
|
62
|
||
|
|
63
|
||
|
|
64
|
||
|
|
65
|
||
|
|
66
|
||
|
|
67
|
||
|
|
68
|
||
|
|
69
|
||
|
|
70
|
||
|
|
71
|
||
|
|
72
|
||
|
|
73
|
||
|
|
74
|
||
|
|
75
|
||
|
|
76
|
||
|
|
77
|
||
|
|
78
|
||
|
|
79
|
||
|
|
80
|
||
|
|
81
|
||
|
|
82
|
||
|
|
83
|
||
|
|
84
|
||
|
|
85
|
||
|
|
86
|
||
|
|
87
|
||
|
|
88
|
||
|
|
89
|
||
|
|
90
|
||
|
|
91
|
||
|
|
92
|
||
|
|
93
|
||
|
|
94
|
||
|
|
95
|
||
|
|
96
|
||
|
|
97
|
||
|
|
98
|
||
|
|
99
|
||
|
|
100
|
||
|
|
101
|
||
|
|
102
|
||
|
|
103
|
||
|
|
104
|
||
|
|
105
|
||
|
|
106
|
||
|
|
107
|
||
|
|
108
|
||
|
|
109
|
||
|
|
110
|
||
|
|
111
|
||
|
|
112
|
||
|
|
113
|
||
|
|
114
|
||
|
|
115
|
||
|
|
116
|
||
|
|
117
|
||
|
|
118
|
||
|
|
119
|
||
|
|
120
|
||
|
|
121
|
||
|
|
122
|
||
|
|
123
|
||
|
|
124
|
||
|
|
125
|
||
|
|
126
|
||
|
|
127
|
||
|
|
128
|
||
|
|
129
|
||
|
|
130
|
||
|
|
131
|
||
|
|
132
|
||
|
|
133
|
||
|
|
134
|
||
|
|
135
|
||
|
|
136
|
||
|
|
137
|
||
|
|
138
|
||
|
|
139
|
||
|
|
140
|
||
|
|
141
|
||
|
|
142
|
||
|
|
143
|
||
|
|
144
|
||
|
|
145
|
||
|
|
146
|
||
|
|
147
|
||
|
|
148
|
||
|
|
149
|
||
|
|
150
|
||
|
|
151
|
||
|
|
152
|
||
|
|
153
|
||
|
|
154
|
||
|
|
155
|
||
|
|
156
|
||
|
|
157
|
||
|
|
158
|
||
|
|
159
|
||
|
|
160
|
||
|
|
161
|
||
|
|
162
|
||
|
|
163
|
||
|
|
164
|
||
|
|
165
|
||
|
|
166
|
||
|
|
167
|
||
|
|
168
|
||
|
|
169
|
||
|
|
170
|
||
|
|
171
|
||
|
|
172
|
||
|
|
173
|
||
|
|
174
|
||
|
|
175
|
||
|
|
176
|
||
|
|
177
|
||
|
|
178
|
||
|
|
179
|
||
|
|
180
|
||
|
|
181
|
||
|
|
182
|
||
|
|
183
|
||
|
|
184
|
||
|
|
185
|
||
|
|
186
|
||
|
|
187
|
||
|
|
188
|
||
|
|
189
|
||
|
|
190
|
||
|
|
191
|
||
|
|
192
|
||
|
|
193
|
||
|
|
194
|
||
|
|
195
|
||
|
|
196
|
||
|
|
197
|
||
|
|
198
|
||
|
|
199
|
||
|
|
200
|
||
|
|
201
|
||
|
|
202
|
||
|
|
203
|
||
|
|
204
|
||
|
|
205
|
||
|
|
206
|
||
|
|
207
|
||
|
|
208
|
||
|
|
209
|
||
|
|
210
|
||
|
|
211
|
||
|
|
212
|
||
|
|
213
|
||
|
|
214
|
||
|
|
215
|
||
|
|
216
|
||
|
|
217
|
||
|
|
218
|
||
|
|
219
|
||
|
|
220</td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">70x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">70x</span>
|
||
|
|
<span class="cline-any cline-yes">1x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">69x</span>
|
||
|
|
<span class="cline-any cline-yes">1x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">68x</span>
|
||
|
|
<span class="cline-any cline-yes">1x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">67x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">67x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">26x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">26x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">26x</span>
|
||
|
|
<span class="cline-any cline-yes">26x</span>
|
||
|
|
<span class="cline-any cline-yes">26x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">24x</span>
|
||
|
|
<span class="cline-any cline-yes">22x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">22x</span>
|
||
|
|
<span class="cline-any cline-yes">61x</span>
|
||
|
|
<span class="cline-any cline-yes">63x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">61x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">59x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">55x</span>
|
||
|
|
<span class="cline-any cline-yes">55x</span>
|
||
|
|
<span class="cline-any cline-yes">8x</span>
|
||
|
|
<span class="cline-any cline-yes">47x</span>
|
||
|
|
<span class="cline-any cline-yes">47x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">45x</span>
|
||
|
|
<span class="cline-any cline-yes">45x</span>
|
||
|
|
<span class="cline-any cline-yes">28x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">26x</span>
|
||
|
|
<span class="cline-any cline-yes">8x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-yes">37x</span>
|
||
|
|
<span class="cline-any cline-yes">37x</span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">37x</span>
|
||
|
|
<span class="cline-any cline-yes">37x</span>
|
||
|
|
<span class="cline-any cline-yes">8x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">29x</span>
|
||
|
|
<span class="cline-any cline-yes">29x</span>
|
||
|
|
<span class="cline-any cline-yes">29x</span>
|
||
|
|
<span class="cline-any cline-yes">112x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-yes">110x</span>
|
||
|
|
<span class="cline-any cline-yes">110x</span>
|
||
|
|
<span class="cline-any cline-yes">6x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">104x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">102x</span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">98x</span>
|
||
|
|
<span class="cline-any cline-yes">98x</span>
|
||
|
|
<span class="cline-any cline-yes">13x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">85x</span>
|
||
|
|
<span class="cline-any cline-yes">85x</span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">81x</span>
|
||
|
|
<span class="cline-any cline-yes">81x</span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">77x</span>
|
||
|
|
<span class="cline-any cline-yes">46x</span>
|
||
|
|
<span class="cline-any cline-yes">77x</span>
|
||
|
|
<span class="cline-any cline-yes">77x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">29x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-yes">45x</span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">39x</span>
|
||
|
|
<span class="cline-any cline-yes">39x</span>
|
||
|
|
<span class="cline-any cline-yes">2x</span>
|
||
|
|
<span class="cline-any cline-yes">37x</span>
|
||
|
|
<span class="cline-any cline-yes">37x</span>
|
||
|
|
<span class="cline-any cline-yes">4x</span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">41x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-yes">19x</span>
|
||
|
|
<span class="cline-any cline-yes">1x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">18x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">34x</span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-yes">1x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">3x</span>
|
||
|
|
<span class="cline-any cline-yes">1x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">32x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-yes">33x</span>
|
||
|
|
<span class="cline-any cline-neutral"> </span>
|
||
|
|
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">'use strict'
|
||
|
|
|
||
|
|
// tar -r
|
||
|
|
const hlo = require('./high-level-opt.js')
|
||
|
|
const Pack = require('./pack.js')
|
||
|
|
const Parse = require('./parse.js')
|
||
|
|
const fs = require('fs')
|
||
|
|
const fsm = require('fs-minipass')
|
||
|
|
const t = require('./list.js')
|
||
|
|
const path = require('path')
|
||
|
|
|
||
|
|
// starting at the head of the file, read a Header
|
||
|
|
// If the checksum is invalid, that's our position to start writing
|
||
|
|
// If it is, jump forward by the specified size (round up to 512)
|
||
|
|
// and try again.
|
||
|
|
// Write the new Pack stream starting there.
|
||
|
|
|
||
|
|
const Header = require('./header.js')
|
||
|
|
|
||
|
|
const r = module.exports = (opt_, files, cb) => {
|
||
|
|
const opt = hlo(opt_)
|
||
|
|
|
||
|
|
if (!opt.file)
|
||
|
|
throw new TypeError('file is required')
|
||
|
|
|
||
|
|
if (opt.gzip)
|
||
|
|
throw new TypeError('cannot append to compressed archives')
|
||
|
|
|
||
|
|
if (!files || !Array.isArray(files) || !files.length)
|
||
|
|
throw new TypeError('no files or directories specified')
|
||
|
|
|
||
|
|
files = Array.from(files)
|
||
|
|
|
||
|
|
return opt.sync ? replaceSync(opt, files)
|
||
|
|
: replace(opt, files, cb)
|
||
|
|
}
|
||
|
|
|
||
|
|
const replaceSync = (opt, files) => {
|
||
|
|
const p = new Pack.Sync(opt)
|
||
|
|
|
||
|
|
let threw = true
|
||
|
|
let fd
|
||
|
|
let position
|
||
|
|
|
||
|
|
try {
|
||
|
|
try {
|
||
|
|
fd = fs.openSync(opt.file, 'r+')
|
||
|
|
} catch (er) {
|
||
|
|
if (er.code === 'ENOENT')
|
||
|
|
fd = fs.openSync(opt.file, 'w+')
|
||
|
|
else
|
||
|
|
throw er
|
||
|
|
}
|
||
|
|
|
||
|
|
const st = fs.fstatSync(fd)
|
||
|
|
const headBuf = Buffer.alloc(512)
|
||
|
|
|
||
|
|
POSITION: for (position = 0; position < st.size; position += 512) {
|
||
|
|
for (let bufPos = 0, bytes = 0; bufPos < 512; bufPos += bytes) {
|
||
|
|
bytes = fs.readSync(
|
||
|
|
fd, headBuf, bufPos, headBuf.length - bufPos, position + bufPos
|
||
|
|
)
|
||
|
|
|
||
|
|
if (position === 0 && headBuf[0] === 0x1f && headBuf[1] === 0x8b)
|
||
|
|
throw new Error('cannot append to compressed archives')
|
||
|
|
|
||
|
|
if (!bytes)
|
||
|
|
break POSITION
|
||
|
|
}
|
||
|
|
|
||
|
|
let h = new Header(headBuf)
|
||
|
|
if (!h.cksumValid)
|
||
|
|
break
|
||
|
|
let entryBlockSize = 512 * Math.ceil(h.size / 512)
|
||
|
|
if (position + entryBlockSize + 512 > st.size)
|
||
|
|
break
|
||
|
|
// the 512 for the header we just parsed will be added as well
|
||
|
|
// also jump ahead all the blocks for the body
|
||
|
|
position += entryBlockSize
|
||
|
|
if (opt.mtimeCache)
|
||
|
|
opt.mtimeCache.set(h.path, h.mtime)
|
||
|
|
}
|
||
|
|
threw = false
|
||
|
|
|
||
|
|
streamSync(opt, p, position, fd, files)
|
||
|
|
} finally {
|
||
|
|
if (threw)
|
||
|
|
try { fs.closeSync(fd) } catch (er) {}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
const streamSync = (opt, p, position, fd, files) => {
|
||
|
|
const stream = new fsm.WriteStreamSync(opt.file, {
|
||
|
|
fd: fd,
|
||
|
|
start: position
|
||
|
|
})
|
||
|
|
p.pipe(stream)
|
||
|
|
addFilesSync(p, files)
|
||
|
|
}
|
||
|
|
|
||
|
|
const replace = (opt, files, cb) => {
|
||
|
|
files = Array.from(files)
|
||
|
|
const p = new Pack(opt)
|
||
|
|
|
||
|
|
const getPos = (fd, size, cb_) => {
|
||
|
|
const cb = (er, pos) => {
|
||
|
|
if (er)
|
||
|
|
fs.close(fd, _ => cb_(er))
|
||
|
|
else
|
||
|
|
cb_(null, pos)
|
||
|
|
}
|
||
|
|
|
||
|
|
let position = 0
|
||
|
|
if (size === 0)
|
||
|
|
return cb(null, 0)
|
||
|
|
|
||
|
|
let bufPos = 0
|
||
|
|
const headBuf = Buffer.alloc(512)
|
||
|
|
const onread = (er, bytes) => {
|
||
|
|
if (er)
|
||
|
|
return cb(er)
|
||
|
|
bufPos += bytes
|
||
|
|
if (bufPos < 512 && bytes)
|
||
|
|
return fs.read(
|
||
|
|
fd, headBuf, bufPos, headBuf.length - bufPos,
|
||
|
|
position + bufPos, onread
|
||
|
|
)
|
||
|
|
|
||
|
|
if (position === 0 && headBuf[0] === 0x1f && headBuf[1] === 0x8b)
|
||
|
|
return cb(new Error('cannot append to compressed archives'))
|
||
|
|
|
||
|
|
// truncated header
|
||
|
|
if (bufPos < 512)
|
||
|
|
return cb(null, position)
|
||
|
|
|
||
|
|
const h = new Header(headBuf)
|
||
|
|
if (!h.cksumValid)
|
||
|
|
return cb(null, position)
|
||
|
|
|
||
|
|
const entryBlockSize = 512 * Math.ceil(h.size / 512)
|
||
|
|
if (position + entryBlockSize + 512 > size)
|
||
|
|
return cb(null, position)
|
||
|
|
|
||
|
|
position += entryBlockSize + 512
|
||
|
|
if (position >= size)
|
||
|
|
return cb(null, position)
|
||
|
|
|
||
|
|
if (opt.mtimeCache)
|
||
|
|
opt.mtimeCache.set(h.path, h.mtime)
|
||
|
|
bufPos = 0
|
||
|
|
fs.read(fd, headBuf, 0, 512, position, onread)
|
||
|
|
}
|
||
|
|
fs.read(fd, headBuf, 0, 512, position, onread)
|
||
|
|
}
|
||
|
|
|
||
|
|
const promise = new Promise((resolve, reject) => {
|
||
|
|
p.on('error', reject)
|
||
|
|
let flag = 'r+'
|
||
|
|
const onopen = (er, fd) => {
|
||
|
|
if (er && er.code === 'ENOENT' && flag === 'r+') {
|
||
|
|
flag = 'w+'
|
||
|
|
return fs.open(opt.file, flag, onopen)
|
||
|
|
}
|
||
|
|
|
||
|
|
if (er)
|
||
|
|
return reject(er)
|
||
|
|
|
||
|
|
fs.fstat(fd, (er, st) => {
|
||
|
|
if (er)
|
||
|
|
return reject(er)
|
||
|
|
getPos(fd, st.size, (er, position) => {
|
||
|
|
if (er)
|
||
|
|
return reject(er)
|
||
|
|
const stream = new fsm.WriteStream(opt.file, {
|
||
|
|
fd: fd,
|
||
|
|
start: position
|
||
|
|
})
|
||
|
|
p.pipe(stream)
|
||
|
|
stream.on('error', reject)
|
||
|
|
stream.on('close', resolve)
|
||
|
|
addFilesAsync(p, files)
|
||
|
|
})
|
||
|
|
})
|
||
|
|
}
|
||
|
|
fs.open(opt.file, flag, onopen)
|
||
|
|
})
|
||
|
|
|
||
|
|
return cb ? promise.then(cb, cb) : promise
|
||
|
|
}
|
||
|
|
|
||
|
|
const addFilesSync = (p, files) => {
|
||
|
|
files.forEach(file => {
|
||
|
|
if (file.charAt(0) === '@')
|
||
|
|
t({
|
||
|
|
file: path.resolve(p.cwd, file.substr(1)),
|
||
|
|
sync: true,
|
||
|
|
noResume: true,
|
||
|
|
onentry: entry => p.add(entry)
|
||
|
|
})
|
||
|
|
else
|
||
|
|
p.add(file)
|
||
|
|
})
|
||
|
|
p.end()
|
||
|
|
}
|
||
|
|
|
||
|
|
const addFilesAsync = (p, files) => {
|
||
|
|
while (files.length) {
|
||
|
|
const file = files.shift()
|
||
|
|
if (file.charAt(0) === '@')
|
||
|
|
return t({
|
||
|
|
file: path.resolve(p.cwd, file.substr(1)),
|
||
|
|
noResume: true,
|
||
|
|
onentry: entry => p.add(entry)
|
||
|
|
}).then(_ => addFilesAsync(p, files))
|
||
|
|
else
|
||
|
|
p.add(file)
|
||
|
|
}
|
||
|
|
p.end()
|
||
|
|
}
|
||
|
|
</pre></td></tr>
|
||
|
|
</table></pre>
|
||
|
|
<div class='push'></div><!-- for sticky footer -->
|
||
|
|
</div><!-- /wrapper -->
|
||
|
|
<div class='footer quiet pad2 space-top1 center small'>
|
||
|
|
Code coverage
|
||
|
|
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Nov 20 2017 16:00:38 GMT-0800 (PST)
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<script src="../../prettify.js"></script>
|
||
|
|
<script>
|
||
|
|
window.onload = function () {
|
||
|
|
if (typeof prettyPrint === 'function') {
|
||
|
|
prettyPrint();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
</script>
|
||
|
|
<script src="../../sorter.js"></script>
|
||
|
|
</body>
|
||
|
|
</html>
|