Class ZipFS

Zip file-backed filesystem Implemented according to the standard: http://pkware.com/documents/casestudies/APPNOTE.TXT

While there are a few zip libraries for JavaScript (e.g. JSZip and zip.js), they are not a good match for ZenFS. In particular, these libraries perform a lot of unneeded data copying, and eagerly decompress every file in the zip file upon loading to check the CRC32. They also eagerly decode strings. Furthermore, these libraries duplicate functionality already present in ZenFS (e.g. UTF-8 decoding and binary data manipulation).

When the filesystem is instantiated, we determine the directory structure of the zip file as quickly as possible. We lazily decompress and check the CRC32 of files. We do not cache decompressed files; if this is a desired feature, it is best implemented as a generic file system wrapper that can cache data from arbitrary file systems.

Current limitations:

  • No encryption.
  • No ZIP64 support.
  • Read-only. Write support would require that we:
    • Keep track of changed/new files.
    • Compress changed files, and generate appropriate metadata for each.
    • Update file offsets for other files in the zip file.
    • Stream it out to a location. This isn't that bad, so we might do this at a later date.

Hierarchy

  • {
        createFile(path: string, flag: string, mode: number): Promise<File>;
        createFileSync(path: string, flag: string, mode: number): File;
        link(srcpath: string, dstpath: string): Promise<void>;
        linkSync(srcpath: string, dstpath: string): void;
        metadata(): FileSystemMetadata;
        mkdir(path: string, mode: number): Promise<void>;
        mkdirSync(path: string, mode: number): void;
        rename(oldPath: string, newPath: string): Promise<void>;
        renameSync(oldPath: string, newPath: string): void;
        rmdir(path: string): Promise<void>;
        rmdirSync(path: string): void;
        sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
        syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
        unlink(path: string): Promise<void>;
        unlinkSync(path: string): void;
    } & ExtractProperties<FileSystem, ((...args: any[]) => Promise<unknown>)> & FileSystem<this>
    • ZipFS

Constructors

  • Parameters

    • name: string
    • data: ArrayBufferLike

    Returns ZipFS

Properties

_disableSync?: boolean

Whether the sync cache should be disabled. Only affects async things.

_time: number = ...
data: ArrayBufferLike
directories: Map<string, Set<string>> = ...
eocd: Header
files: Map<string, FileEntry> = ...
name: string

Accessors

  • get numberOfCentralDirectoryEntries(): number
  • Returns number

Methods

  • Parameters

    • path: string
    • flag: string
    • mode: number

    Returns Promise<File>

  • Parameters

    • path: string
    • flag: string
    • mode: number

    Returns File

  • Test whether or not path exists.

    Parameters

    • path: string

    Returns Promise<boolean>

  • Test whether or not path exists.

    Parameters

    • path: string

    Returns boolean

  • Parameters

    • srcpath: string
    • dstpath: string

    Returns Promise<void>

  • Parameters

    • srcpath: string
    • dstpath: string

    Returns void

  • Get metadata about the current file system

    Returns FileSystemMetadata

  • Parameters

    • path: string
    • mode: number

    Returns Promise<void>

  • Parameters

    • path: string
    • mode: number

    Returns void

  • Opens the file at path with flag. The file must exist.

    Parameters

    • path: string

      The path to open.

    • flag: string

      The flag to use when opening the file.

    Returns Promise<File>

  • Opens the file at path with flag. The file must exist.

    Parameters

    • path: string

      The path to open.

    • flag: string

      The flag to use when opening the file.

    Returns NoSyncFile<ZipFS>

  • Parameters

    • path: string

    Returns Promise<string[]>

  • Parameters

    • path: string

    Returns string[]

  • Returns Promise<void>

  • Parameters

    • oldPath: string
    • newPath: string

    Returns Promise<void>

  • Parameters

    • oldPath: string
    • newPath: string

    Returns void

  • Parameters

    • path: string

    Returns Promise<void>

  • Parameters

    • path: string

    Returns void

  • Parameters

    • path: string

    Returns Promise<Stats>

  • Parameters

    • path: string

    Returns Stats

  • Parameters

    • path: string
    • data: Uint8Array
    • stats: Readonly<Stats>

    Returns Promise<void>

  • Parameters

    • path: string
    • data: Uint8Array
    • stats: Readonly<Stats>

    Returns void

  • Parameters

    • path: string

    Returns Promise<void>

  • Parameters

    • path: string

    Returns void

  • Locates the end of central directory record at the end of the file. Throws an exception if it cannot be found.

    Parameters

    • data: ArrayBufferLike

    Returns Header

    Unfortunately, the comment is variable size and up to 64K in size. We assume that the magic signature does not appear in the comment, and in the bytes between the comment and the signature. Other ZIP implementations make this same assumption, since the alternative is to read thread every entry in the file.

    Offsets in this function are negative (i.e. from the end of the file).

    There is no byte alignment on the comment