Skip to content
FutureBlitz

    Install

    Import std.compress.vfs

    std.compress.vfs

    Zips mounted in std.io's virtual file system.

    std.compress's zips in std.io's virtual file system: a ZipSource reads a zip's files as a VfsSource, and a Vfs's MountZip mounts one, as an app mounts its packed data.

    Examples

    Local zip = ZipWriter()
    zip.Add("docs/a.txt", "a".Bytes)
    Local source = Try ZipSource(Try Zip.Read(zip.Finish()))
    Local a = Try source.Read("docs/a.txt")
    Expect(a == "a".Bytes)
    Expect((Try source.KindAt("docs")) == FileKind.DIRECTORY)

    std/compress/vfs.fb

    Types

    ZipSource class

    Public Class ZipSource Implements VfsSource

    A zip's files as a source, by their names: each file's name is its path, with '/' (or '') between folders, and the folders are the ones its entries name or go through. An entry whose name goes above the zip's root, or has no names once its "."s and ".."s are taken out, isn't in it, so a zip can't reach past where it's mounted, and neither is a link. Of the entries a name has, the last is the file, as ZipReader.Read takes it. A read decompresses the file from the zip each time.

    std/compress/vfs.fb, line 32

    • Public New(reader: ZipReader) Throws IOError constructor #

      A source of the zip a ZipReader reads, which it keeps. Throws an IOError of INVALID_DATA when the zip's entries make one place a file and a folder too.

    • Public Method Read(path: String): UInt8[]? Throws IOError method #

      The bytes of the file at path in the zip, or Null when it has none there. Throws an IOError when the entry is broken, as ZipReader's ReadAt does.

    • Public Method KindAt(path: String): FileKind? Throws IOError method #

      Whether path is a file or a folder in the zip, or Null when it's neither.

    • Public Method List(path: String): (String, FileKind)[]? Throws IOError method #

      The names in the folder at path in the zip, each with whether it's a file or a folder, or Null when there's no folder there.

    Extends

    Vfs extend

    Extend Vfs

    Mounting a zip in a Vfs, as its files.

    std/compress/vfs.fb, line 106

    • @PanicsAtCaller Public Method MountZip(at: Path, data: UInt8[]) Throws IOError method #

      Mounts the zip in data, which it copies, at at, as a ZipSource. Throws an IOError of INVALID_DATA when the data isn't a zip, or ends early, or as a ZipSource does, and panics for a path that goes above the root, as Mount does.

      Examples

      Local zip = ZipWriter()
      zip.Add("levels/one.txt", "first".Bytes)
      Local files = Vfs()
      Try files.MountZip(Path("data"), zip.Finish())
      Expect(Try files.ReadText(Path("data/levels/one.txt")) == "first")
      Expect(files.DirExists(Path("data/levels")))

    Report an issue with this page or with FutureBlitz on GitHub.