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.
-
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.
-
The bytes of the file at
pathin the zip, or Null when it has none there. Throws an IOError when the entry is broken, as ZipReader's ReadAt does. -
Whether
pathis a file or a folder in the zip, or Null when it's neither. -
The names in the folder at
pathin 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.
-
Mounts the zip in
data, which it copies, atat, as a ZipSource. Throws an IOError of INVALID_DATA when thedataisn'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.