@@ -6,18 +6,13 @@ import * as constants from './constants';
6
6
7
7
// Computes the checksum by summing up all the bytes in the header
8
8
function computeChecksum ( header : Uint8Array ) : number {
9
- if ( ! header . slice ( 148 , 156 ) . every ( ( byte ) => byte === 32 ) ) {
10
- throw new errors . ErrorVirtualTarInvalidHeader (
11
- 'Checksum field is not properly initialized with spaces' ,
12
- ) ;
13
- }
14
9
return header . reduce ( ( sum , byte ) => sum + byte , 0 ) ;
15
10
}
16
11
17
- function createHeader (
12
+ function generateHeader (
18
13
filePath : string ,
19
- stat : FileStat ,
20
14
type : EntryType ,
15
+ stat : FileStat ,
21
16
) : Uint8Array {
22
17
// TODO: implement long-file-name headers
23
18
if ( filePath . length < 1 || filePath . length > 255 ) {
@@ -26,14 +21,6 @@ function createHeader(
26
21
) ;
27
22
}
28
23
29
- // The file path must not contain any directories, and must only contain a
30
- // file name. This guard checks that.
31
- if ( filePath . includes ( '/' ) ) {
32
- throw new errors . ErrorVirtualTarInvalidFileName (
33
- 'File name must not contain /' ,
34
- ) ;
35
- }
36
-
37
24
// As the size does not matter for directories, it can be undefined. However,
38
25
// if the header is being generated for a file, then it needs to have a valid
39
26
// size. This guard checks that.
@@ -202,14 +189,11 @@ function createHeader(
202
189
return header ;
203
190
}
204
191
205
- // Creates blocks marking the ned of the header. Returns one buffer of 1024
206
- // bytes filled with nulls. This aligns with the tar end-of-archive marker
207
- // being two null-filled blocks.
208
- function generateEndMarker ( ) {
209
- return [
210
- new Uint8Array ( constants . BLOCK_SIZE ) ,
211
- new Uint8Array ( constants . BLOCK_SIZE ) ,
212
- ] ;
192
+ // Creates a single null block. A null block is a block filled with all zeros.
193
+ // This is needed to end the archive, as two of these blocks mark the end of
194
+ // archive.
195
+ function generateNullChunk ( ) {
196
+ return new Uint8Array ( constants . BLOCK_SIZE ) ;
213
197
}
214
198
215
- export { createHeader , generateEndMarker } ;
199
+ export { generateHeader , generateNullChunk } ;
0 commit comments