@@ -6,18 +6,13 @@ import * as constants from './constants';
66
77// Computes the checksum by summing up all the bytes in the header
88function 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- }
149 return header . reduce ( ( sum , byte ) => sum + byte , 0 ) ;
1510}
1611
17- function createHeader (
12+ function generateHeader (
1813 filePath : string ,
19- stat : FileStat ,
2014 type : EntryType ,
15+ stat : FileStat ,
2116) : Uint8Array {
2217 // TODO: implement long-file-name headers
2318 if ( filePath . length < 1 || filePath . length > 255 ) {
@@ -26,14 +21,6 @@ function createHeader(
2621 ) ;
2722 }
2823
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-
3724 // As the size does not matter for directories, it can be undefined. However,
3825 // if the header is being generated for a file, then it needs to have a valid
3926 // size. This guard checks that.
@@ -202,14 +189,11 @@ function createHeader(
202189 return header ;
203190}
204191
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 ) ;
213197}
214198
215- export { createHeader , generateEndMarker } ;
199+ export { generateHeader , generateNullChunk } ;
0 commit comments