1
1
// Based on https://github.com/gera2ld/tarjs
2
2
// and https://github.com/ankitrohatgi/tarballjs/blob/master/tarball.js
3
- export enum TarFileType {
4
- File = "0" ,
5
- Dir = "5" ,
3
+ type TarFileType = string
4
+ // Added the most common codes
5
+ export const TarFileTypeCodes = {
6
+ File : "0" ,
7
+ Dir : "5" ,
6
8
}
7
9
const encoder = new TextEncoder ( )
8
10
const utf8Encode = ( input : string ) => encoder . encode ( input )
@@ -131,13 +133,7 @@ export class TarReader {
131
133
private readFileType ( offset : number ) {
132
134
const typeView = new Uint8Array ( this . buffer , offset + 156 , 1 )
133
135
const typeStr = String . fromCharCode ( typeView [ 0 ] )
134
- if ( typeStr === "0" ) {
135
- return TarFileType . File
136
- } else if ( typeStr === "5" ) {
137
- return TarFileType . Dir
138
- } else {
139
- throw new Error ( "No supported file type" )
140
- }
136
+ return typeStr
141
137
}
142
138
143
139
private readFileSize ( offset : number ) {
@@ -192,7 +188,7 @@ export class TarWriter {
192
188
const size = ( data as ArrayBuffer ) . byteLength ?? ( file as Blob ) . size
193
189
const item : ITarWriteItem = {
194
190
name,
195
- type : TarFileType . File ,
191
+ type : TarFileTypeCodes . File ,
196
192
data,
197
193
size,
198
194
opts,
@@ -203,7 +199,7 @@ export class TarWriter {
203
199
addFolder ( name : string , opts ?: Partial < ITarWriteOptions > ) {
204
200
this . fileData . push ( {
205
201
name,
206
- type : TarFileType . Dir ,
202
+ type : TarFileTypeCodes . Dir ,
207
203
data : null ,
208
204
size : 0 ,
209
205
opts,
@@ -315,7 +311,7 @@ export class TarWriter {
315
311
const { uid, gid, mode, mtime, user, group } = {
316
312
uid : 1000 ,
317
313
gid : 1000 ,
318
- mode : fileType === TarFileType . File ? 0o664 : 0o775 ,
314
+ mode : fileType === TarFileTypeCodes . File ? 0o664 : 0o775 ,
319
315
mtime : ~ ~ ( Date . now ( ) / 1000 ) ,
320
316
user : "tarballjs" ,
321
317
group : "tarballjs" ,
0 commit comments