@haxall/haxall
    Preparing search index...

    Class Zip

    Zip is used to read/write compressed zip files and streams. Zip may be used in three modes:

    1. Zip.open is used to read a random access file and provides access to the entire contents with the ability to read select entries
    2. Zip.read is used to read a zip file from an input stream. Each entry is pulled off the stream using readNext
    3. Zip.write is used to write a zip file to an output stream. Each entry is written to the stream using writeNext

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

    • Close this zip file for reading and writing. If this zip file is reading or writing a stream, then the underlying stream is also closed. This method is guaranteed to never throw an IOErr. Return true if the close was successful or false if an error occurred.

      Returns boolean

    • Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:

      this < that   =>  <0
      this == that => 0
      this > that => >0

      This method may also be accessed via the < <= <=> >= and > shortcut operators. If not overridden the default implementation compares the toStr representations. Also see docLang.

      Examples:

      3.compare(8)  =>  -1
      8.compare(3) => 1
      8.compare(8) => 0
      3 <=> 8 => -1 // shortcut for 3.compare(8)

      Parameters

      Returns number

    • Return the contents of this zip as a map of Files. The Uri keys will start with a slash and be relative to this zip file. Return null if using streams.

      Returns Map<Uri, File>

    • Compare this object to the specified for equality. This method may be accessed via the == and != shortcut operators. If not overridden the default implementation compares for reference equality using the === operator. If this method is overridden, then hash() must also be overridden such that any two objects which return true for equals() must return the same value for hash(). This method must accept null and return false.

      Parameters

      Returns boolean

    • Get the underlying file or null if using streams.

      Returns File

    • Finish writing the contents of this zip file, but leave the underlying OutStream open. This method is guaranteed to never throw an IOErr. Return true if the stream was finished successfully or false if an error occurred. Throw UnsupportedErr if zip is not writing to an output stream.

      Returns boolean

    • Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.

      Returns number

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Call the specified function for every entry in the zip. Use the File's input stream to read the file contents. Some file meta-data such as size may not be available. Throw UnsupportedErr if not reading from an input stream.

      Parameters

      • c: (arg0: File) => void

      Returns void

    • Read the next entry in the zip. Use the File's input stream to read the file contents. Some file meta-data such as size may not be available. Return null if at end of zip file. Throw UnsupportedErr if not reading from an input stream.

      Returns File

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • If file is not null then return file.toStr, otherwise return a suitable string representation.

      Returns string

    • Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:

      a->x        a.trap("x", null)
      a->x() a.trap("x", null)
      a->x = b a.trap("x", [b])
      a->x(b) a.trap("x", [b])
      a->x(b, c) a.trap("x", [b, c])

      The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Append a new file to the end of this zip file and return an OutStream which may be used to write the file contents. The Uri must not contain a query or fragment; it may optionally start with a slash. Closing the OutStream will close only this file entry - use Zip.close() when finished writing the entire zip file. Throw UnsupportedErr if zip is not writing to an output stream.

      Next entry options:

      • comment: Str entry comment
      • crc: Int CRC-32 of the uncompressed data
      • extra: Buf for extra bytes data field
      • level: Int between 9 (best compression) to 0 (no compression)
      • compressedSize: Int for compressed size of data
      • uncompressedSize: Int for uncompressed size of data

      NOTE: setting level to 0 sets method to STORE, else to DEFLATED.

      Examples:

      out := zip.writeNext(`/docs/test.txt`)
      out.writeLine("test")
      out.close

      Parameters

      Returns OutStream

    • Construct a new deflate input stream which wraps the given input stream and inflates data written using the "deflate" compression format. Options:

      • nowrap: Bool false to suppress defalate header and adler checksum

      Parameters

      Returns InStream

    • Construct a new deflate output stream which wraps the given output stream, and compresses data using the "deflate" compression format. Options:

      • level: Int between 9 (best compression) to 0 (no compression)
      • nowrap: Bool false to suppress defalate header and adler checksum

      Parameters

      Returns OutStream

    • Write x.toStr to standard output followed by newline. If x is null then print "null". If no argument is provided then print an empty line.

      Parameters

      Returns void

    • Construct a new GZIP input stream which wraps the given input stream.

      Parameters

      Returns InStream

    • Construct a new GZIP output stream which wraps the given output stream.

      Parameters

      Returns OutStream

    • Open the specified file as a zip file for reading. If the specified file does not exist, is not a valid file, or does not support random access then throw IOErr.

      Example:

      zip := Zip.open(File(`test.zip`))
      txt := zip.contents[`/notice.txt`].readAllStr
      zip.close

      Parameters

      Returns Zip

    • Create a Zip used to read a zip file from the specified input stream.

      Example:

      zip := Zip.read(File(`test.zip`).in)
      File? entry
      while ((entry = zip.readNext()) != null)
      {
      data := entry.readAllBuf
      echo("$entry size=$data.size")
      }
      zip.close

      Parameters

      Returns Zip

    • Static utility to unzip a zip file to the given directory. Raise exception if there are any failures. Return number of files unzipped on success.

      Parameters

      Returns number

    • Create a Zip used to write a zip file to the specified output stream.

      Example:

      zip := Zip.write(File(`test.zip`).out)
      out := zip.writeNext(`/path/hello.txt`)
      out.writeLine("hello zip")
      out.close
      zip.close

      Parameters

      Returns Zip