Options
All
  • Public
  • Public/Protected
  • All
Menu

Zip file-backed filesystem Implemented according to the standard: http://www.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 BrowserFS. 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 BrowserFS (e.g. UTF-8 decoding and binary data manipulation).

This filesystem takes advantage of BrowserFS's Buffer implementation, which efficiently represents the zip file in memory (in both ArrayBuffer-enabled browsers and non-ArrayBuffer browsers), and which can neatly be 'sliced' without copying data. Each struct defined in the standard is represented with a buffer slice pointing to an offset in the zip file, and has getters for each field. As we anticipate that this data will not be read often, we choose not to store each struct field in the JavaScript object; instead, to reduce memory consumption, we retrieve it directly from the binary data each time it is requested.

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.

For inflation, we use pako's implementation: https://github.com/nodeca/pako

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

Implements

Index

Constructors

constructor

  • new ZipFS(input: Buffer | ZipTOC, name?: string, deprecateMsg?: boolean): ZipFS
  • Deprecated. Please use ZipFS.Create() method to construct ZipFS objects.

    Parameters

    • input: Buffer | ZipTOC
    • Default value name: string = ""
    • Default value deprecateMsg: boolean = true

    Returns ZipFS

Properties

Static CompressionMethod

CompressionMethod: CompressionMethod = CompressionMethod

Methods

appendFile

appendFileSync

  • appendFileSync(fname: string, data: any, encoding: string | null, flag: FileFlag, mode: number): void

chmod

chmodSync

  • chmodSync(p: string, isLchmod: boolean, mode: number): void

chown

  • chown(p: string, isLchown: boolean, uid: number, gid: number, cb: BFSOneArgCallback): void

chownSync

  • chownSync(p: string, isLchown: boolean, uid: number, gid: number): void

createFile

createFileSync

  • createFileSync(p: string, flag: FileFlag, mode: number): File

diskSpace

  • diskSpace(path: string, cb: function): void

exists

  • exists(p: string, cb: function): void

existsSync

  • existsSync(p: string): boolean

getCentralDirectoryEntry

getCentralDirectoryEntryAt

getEndOfCentralDirectory

getName

  • getName(): string

getNumberOfCentralDirectoryEntries

  • getNumberOfCentralDirectoryEntries(): number

isReadOnly

  • isReadOnly(): boolean

link

linkSync

  • linkSync(srcpath: string, dstpath: string): void

mkdir

mkdirSync

  • mkdirSync(p: string, mode: number): void

open

openFile

openFileSync

  • openFileSync(p: string, flag: FileFlag, mode: number): File
  • Opens the file at path p with the given flag. The file must exist.

    Parameters

    • p: string

      The path to open.

    • flag: FileFlag

      The flag to use when opening the file.

    • mode: number

    Returns File

    A File object corresponding to the opened file.

openSync

  • openSync(path: string, flags: FileFlag, mode: number): File

readFile

  • readFile(fname: string, encoding: string | null, flag: FileFlag, cb: BFSCallback<string | Buffer>): void

readFileSync

  • readFileSync(fname: string, encoding: string, flag: FileFlag): any

readdir

readdirSync

  • readdirSync(path: string): string[]

readlink

readlinkSync

  • readlinkSync(p: string): string

realpath

  • realpath(p: string, cache: object, cb: BFSCallback<string>): void

realpathSync

  • realpathSync(p: string, cache: object): string

rename

renameSync

  • renameSync(oldPath: string, newPath: string): void

rmdir

rmdirSync

  • rmdirSync(p: string): void

stat

statSync

  • statSync(path: string, isLstat: boolean): Stats

supportsLinks

  • supportsLinks(): boolean

supportsProps

  • supportsProps(): boolean

supportsSynch

  • supportsSynch(): boolean

symlink

  • symlink(srcpath: string, dstpath: string, type: string, cb: BFSOneArgCallback): void

symlinkSync

  • symlinkSync(srcpath: string, dstpath: string, type: string): void

truncate

truncateSync

  • truncateSync(p: string, len: number): void

unlink

unlinkSync

  • unlinkSync(p: string): void

utimes

utimesSync

  • utimesSync(p: string, atime: Date, mtime: Date): void

writeFile

writeFileSync

  • writeFileSync(fname: string, data: any, encoding: string | null, flag: FileFlag, mode: number): void

Static Create

Static RegisterDecompressionMethod

  • Parameters

    • m: CompressionMethod
    • fcn: function
        • (data: Buffer, compressedSize: number, uncompressedSize: number, flags: number): Buffer
        • Parameters

          • data: Buffer
          • compressedSize: number
          • uncompressedSize: number
          • flags: number

          Returns Buffer

    Returns void

Static computeIndex

  • computeIndex(data: Buffer, cb: function, deprecateMsg?: boolean): void
  • Deprecated. Please use ZipFS.Create() method instead.

    Parameters

    • data: Buffer
    • cb: function
        • Parameters

          Returns void

    • Default value deprecateMsg: boolean = true

    Returns void

Static isAvailable

  • isAvailable(): boolean

Generated using TypeDoc