Skip to content

fix(site): remove tar file type limitation #7817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions site/src/utils/tar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TarReader, TarWriter, ITarFileInfo, TarFileType } from "./tar"
import { TarReader, TarWriter, ITarFileInfo, TarFileTypeCodes } from "./tar"

const mtime = 1666666666666

Expand Down Expand Up @@ -56,5 +56,5 @@ function verifyFile(

function verifyFolder(info: ITarFileInfo, expected: { name: string }) {
expect(info.name).toEqual(expected.name)
expect(info.type).toEqual(TarFileType.Dir)
expect(info.type).toEqual(TarFileTypeCodes.Dir)
}
22 changes: 9 additions & 13 deletions site/src/utils/tar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Based on https://github.com/gera2ld/tarjs
// and https://github.com/ankitrohatgi/tarballjs/blob/master/tarball.js
export enum TarFileType {
File = "0",
Dir = "5",
type TarFileType = string
// Added the most common codes
export const TarFileTypeCodes = {
File: "0",
Dir: "5",
}
const encoder = new TextEncoder()
const utf8Encode = (input: string) => encoder.encode(input)
Expand Down Expand Up @@ -131,13 +133,7 @@ export class TarReader {
private readFileType(offset: number) {
const typeView = new Uint8Array(this.buffer, offset + 156, 1)
const typeStr = String.fromCharCode(typeView[0])
if (typeStr === "0") {
return TarFileType.File
} else if (typeStr === "5") {
return TarFileType.Dir
} else {
throw new Error("No supported file type")
}
return typeStr
}

private readFileSize(offset: number) {
Expand Down Expand Up @@ -192,7 +188,7 @@ export class TarWriter {
const size = (data as ArrayBuffer).byteLength ?? (file as Blob).size
const item: ITarWriteItem = {
name,
type: TarFileType.File,
type: TarFileTypeCodes.File,
data,
size,
opts,
Expand All @@ -203,7 +199,7 @@ export class TarWriter {
addFolder(name: string, opts?: Partial<ITarWriteOptions>) {
this.fileData.push({
name,
type: TarFileType.Dir,
type: TarFileTypeCodes.Dir,
data: null,
size: 0,
opts,
Expand Down Expand Up @@ -315,7 +311,7 @@ export class TarWriter {
const { uid, gid, mode, mtime, user, group } = {
uid: 1000,
gid: 1000,
mode: fileType === TarFileType.File ? 0o664 : 0o775,
mode: fileType === TarFileTypeCodes.File ? 0o664 : 0o775,
mtime: ~~(Date.now() / 1000),
user: "tarballjs",
group: "tarballjs",
Expand Down