Top Documents Download Gallery Repository
Are you looking for a Software Engineer? Check Here

58zip Module

The zip module provides measures to read/write ZIP files.

58.1zip.reader Class

The zip.reader class provides methods to read contents and to get information in a ZIP file through stream instance. An instance of stream class created by the methods includes a property named stat, a zip.stat instance, which provides information such as filename and created time stamp that are contained in the ZIP file.

Below is an example to list filenames in a ZIP file:

import(zip)
zip.reader('foo.zip') {|r|
    println(r.entries():*stat:*filename)
}

Below is an example to print a content of a text file that is stored in a ZIP file:

import(zip)
zip.reader('foo.zip') {|r|
    print(r.entry('README.txt').readlines())
}

58.1.1Constructor

zip.reader
zip.reader(stream:stream:r) {block?}
Creates zip.reader instance from the specified stream.

If block is specified, it would be evaluated with a block parameter |reader:zip.reader|, where reader is the created instance. In this case, the block's result would become the function's returned value.

58.1.2Method

zip.reader#entry
zip.reader#entry(name:string) {block?}
Seeks entry in the zip file that matches the specified name and returns a stream instance associated with the entry.

If block is specified, it would be evaluated with a block parameter |s:stream|, where s is the created instance. In this case, the block's result would become the function's returned value.

zip.reader#entries
zip.reader#entries() {block?}
Creates an iterator instance that returns stream instances associated with each entry in the ZIP file.

In default, this returns an iterator as its result value. Specifying the following attributes would customize the returned value:

See the chapter of Mapping Process in Gura Language Manual for the detail.

If a block is specified, it would be evaluated repeatingly with block parameters |value, idx:number| where value is the iterated value and idx the loop index starting from zero. In this case, the last evaluated value of the block would be the result value. If one of the attributes listed above is specified, an iterator or a list of the evaluated value would be returned.

58.2zip.writer Class

The zip.writer class provides methods to add entries to a ZIP file. When an instance of zip.writer is created, a new ZIP file would be created.

Below is an exapmple to create a ZIP archive file that contains three entries:

import(zip)
zip.writer('foo.zip') {|w|
    w.add('file1.txt')
    w.add('file2.txt')
    w.add('file3.txt')
    w.close()
}		

58.2.1Constructor

zip.writer
zip.writer(stream:stream:w, compression?:symbol) {block?}
Creates zip.writer instance from the stream.

Argument compression specifies the compression method and takes one of the following symbol.

If block is specified, it would be evaluated with a block parameter |writer:zip.writer|, where writer is the created instance. In this case, the block's result would become the function's returned value.

58.2.2Method

zip.writer#add
zip.writer#add(stream:stream:r, filename?:string, compression?:symbol):map:reduce
Reads data from stream and adds it to the zip file. Entry name is decided by the file name associated with the stream unless it's specified by argument filename.

Argument compression specifies the compression method and takes one of the following symbol.

zip.writer#close
zip.writer#close():void
Closes the zip file after flushing cached data.

58.3zip.stat Class

The zip.stat class provides information of entries in a ZIP file.

58.3.1Property

Property Type R/W Explanation
filename string R
comment string R
mtime datetime R
crc32 number R
compression_method number R
size number R
compressed_size number R
attributes number R

58.4Thanks

This module uses zlib and bzip2 library which are distributed in the following sites:


Copyright (C) 2011-2017 ypsitau