szip: change documentation style (#8883)

pull/8904/head
StunxFS 2021-02-22 08:59:36 -04:00 committed by GitHub
parent b2cdd2cac0
commit ac1c4932e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 144 deletions

View File

@ -37,7 +37,7 @@ fn C.zip_entry_fread(&Zip, byteptr) int
fn C.zip_total_entries(&Zip) int fn C.zip_total_entries(&Zip) int
// Ref - miniz.h // compression level - ref: miniz.h
const ( const (
no_compression = 0 no_compression = 0
best_speed = 1 best_speed = 1
@ -53,18 +53,12 @@ const (
m_append = `a` m_append = `a`
) )
/* // open opens zip archive with compression level using the given mode.<br>
open opens zip archive with compression level using the given mode. // compression levels: 0-9 are the standard zlib-style levels.<br>
// modes:<br>
@param zipname zip archive file name. // - 'r': opens a file for reading/extracting (the file must exists).<br>
@param level compression level (0-9 are the standard zlib-style levels). // - 'w': creates an empty file for writing.<br>
@param mode file access mode. // - 'a': appends to an existing archive.
- 'r': opens a file for reading/extracting (the file must exists).
- 'w': creates an empty file for writing.
- 'a': appends to an existing archive.
@return the zip archive handler or NULL on error
*/
pub fn open(name string, level int, mode byte) ?&Zip { pub fn open(name string, level int, mode byte) ?&Zip {
mut nlevel := level mut nlevel := level
if (nlevel & 0xF) > szip.uber_compression { if (nlevel & 0xF) > szip.uber_compression {
@ -83,27 +77,15 @@ pub fn open(name string, level int, mode byte) ?&Zip {
return p_zip return p_zip
} }
/* // close closes the zip archive, releases resources - always finalize.
close closes the zip archive, releases resources - always finalize.
@param zip zip archive handler.
*/
pub fn (mut z Zip) close() { pub fn (mut z Zip) close() {
C.zip_close(z) C.zip_close(z)
} }
/* // open_entry opens an entry by name in the zip archive.
open_entry opens an entry by name in the zip archive. // For zip archive opened in 'w' or 'a' mode the function will append
// a new entry. In readonly mode the function tries to locate the entry
For zip archive opened in 'w' or 'a' mode the function will append // in global dictionary.
a new entry. In readonly mode the function tries to locate the entry
in global dictionary.
@param zip zip archive handler.
@param entryname an entry name in local dictionary.
@return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (mut zentry Zip) open_entry(name string) ? { pub fn (mut zentry Zip) open_entry(name string) ? {
res := C.zip_entry_open(zentry, name.str) res := C.zip_entry_open(zentry, name.str)
if res == -1 { if res == -1 {
@ -111,31 +93,18 @@ pub fn (mut zentry Zip) open_entry(name string) ? {
} }
} }
/* // close_entry closes a zip entry, flushes buffer and releases resources.
* close_entry closes a zip entry, flushes buffer and releases resources.
*
* @param zip zip archive handler.
*
* @return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (mut zentry Zip) close_entry() { pub fn (mut zentry Zip) close_entry() {
C.zip_entry_close(zentry) C.zip_entry_close(zentry)
} }
/* // name returns a local name of the current zip entry.
name returns a local name of the current zip entry. // The main difference between user's entry name and local entry name
// is optional relative path.
The main difference between user's entry name and local entry name // Following .ZIP File Format Specification - the path stored MUST not contain
is optional relative path. // a drive or device letter, or a leading slash.
Following .ZIP File Format Specification - the path stored MUST not contain // All slashes MUST be forward slashes '/' as opposed to backwards slashes '\'
a drive or device letter, or a leading slash. // for compatibility with Amiga and UNIX file systems etc.
All slashes MUST be forward slashes '/' as opposed to backwards slashes '\'
for compatibility with Amiga and UNIX file systems etc.
@param zip: zip archive handler.
@return the pointer to the current zip entry name, or NULL on error.
*/
pub fn (mut zentry Zip) name() string { pub fn (mut zentry Zip) name() string {
name := C.zip_entry_name(zentry) name := C.zip_entry_name(zentry)
if name == 0 { if name == 0 {
@ -144,13 +113,7 @@ pub fn (mut zentry Zip) name() string {
return unsafe { tos_clone(name) } return unsafe { tos_clone(name) }
} }
/* /// index returns an index of the current zip entry.
index returns an index of the current zip entry.
@param zip zip archive handler.
@return the index on success, negative number (< 0) on error.
*/
pub fn (mut zentry Zip) index() ?int { pub fn (mut zentry Zip) index() ?int {
index := int(C.zip_entry_index(zentry)) index := int(C.zip_entry_index(zentry))
if index == -1 { if index == -1 {
@ -159,15 +122,8 @@ pub fn (mut zentry Zip) index() ?int {
return index // must be check for INVALID_VALUE return index // must be check for INVALID_VALUE
} }
/* // is_dir determines if the current zip entry is a directory entry.
isdir determines if the current zip entry is a directory entry. pub fn (mut zentry Zip) is_dir() ?bool {
@param zip zip archive handler.
@return the return code - 1 (true), 0 (false), negative number (< 0) on
error.
*/
pub fn (mut zentry Zip) isdir() ?bool {
isdir := C.zip_entry_isdir(zentry) isdir := C.zip_entry_isdir(zentry)
if isdir < 0 { if isdir < 0 {
return error('szip: cannot check entry type') return error('szip: cannot check entry type')
@ -175,37 +131,17 @@ pub fn (mut zentry Zip) isdir() ?bool {
return isdir == 1 return isdir == 1
} }
/* // size returns an uncompressed size of the current zip entry.
size returns an uncompressed size of the current zip entry.
@param zip zip archive handler.
@return the uncompressed size in bytes.
*/
pub fn (mut zentry Zip) size() u64 { pub fn (mut zentry Zip) size() u64 {
return C.zip_entry_size(zentry) return C.zip_entry_size(zentry)
} }
/* // crc32 returns CRC-32 checksum of the current zip entry.
crc32 returns CRC-32 checksum of the current zip entry.
@param zip zip archive handler.
@return the CRC-32 checksum.
*/
pub fn (mut zentry Zip) crc32() u32 { pub fn (mut zentry Zip) crc32() u32 {
return C.zip_entry_crc32(zentry) return C.zip_entry_crc32(zentry)
} }
/* // write_entry compresses an input buffer for the current zip entry.
write_entry compresses an input buffer for the current zip entry.
@param zip zip archive handler.
@param buf input buffer.
@param bufsize input buffer size (in bytes).
@return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (mut zentry Zip) write_entry(data []byte) ? { pub fn (mut zentry Zip) write_entry(data []byte) ? {
if (data[0] & 0xff) == -1 { if (data[0] & 0xff) == -1 {
return error('szip: cannot write entry') return error('szip: cannot write entry')
@ -216,14 +152,7 @@ pub fn (mut zentry Zip) write_entry(data []byte) ? {
} }
} }
/* // create_entry compresses a file for the current zip entry.
create_entry compresses a file for the current zip entry.
@param zip zip archive handler.
@param filename input file.
@return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (mut zentry Zip) create_entry(name string) ? { pub fn (mut zentry Zip) create_entry(name string) ? {
res := C.zip_entry_fwrite(zentry, name.str) res := C.zip_entry_fwrite(zentry, name.str)
if res != 0 { if res != 0 {
@ -231,21 +160,10 @@ pub fn (mut zentry Zip) create_entry(name string) ? {
} }
} }
/* // read_entry extracts the current zip entry into output buffer.
read_entry extracts the current zip entry into output buffer. // The function allocates sufficient memory for an output buffer.
// NOTE: remember to release the memory allocated for an output buffer.
The function allocates sufficient memory for an output buffer. // for large entries, please take a look at zip_entry_extract function.
@param zip zip archive handler.
@param buf output buffer.
@param bufsize output buffer size (in bytes).
@note remember to release the memory allocated for an output buffer.
for large entries, please take a look at zip_entry_extract function.
@return the return code - the number of bytes actually read on success.
Otherwise a -1 on error.
*/
pub fn (mut zentry Zip) read_entry() ?voidptr { pub fn (mut zentry Zip) read_entry() ?voidptr {
mut buf := voidptr(0) mut buf := voidptr(0)
mut bsize := i64(0) mut bsize := i64(0)
@ -256,14 +174,7 @@ pub fn (mut zentry Zip) read_entry() ?voidptr {
return buf return buf
} }
/* // extract_entry extracts the current zip entry into output file.
extract_entry extracts the current zip entry into output file.
@param zip zip archive handler.
@param filename output file.
@return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (mut zentry Zip) extract_entry(path string) ? { pub fn (mut zentry Zip) extract_entry(path string) ? {
if C.access(charptr(path.str), 0) == -1 { if C.access(charptr(path.str), 0) == -1 {
return error('Cannot open file for extracting, file not exists') return error('Cannot open file for extracting, file not exists')
@ -276,32 +187,17 @@ pub fn (mut zentry Zip) extract_entry(path string) ? {
/* /*
extract extracts the current zip entry using a callback function (on_extract). extract extracts the current zip entry using a callback function (on_extract).
@param zip zip archive handler.
@param on_extract callback function.
@param arg opaque pointer (optional argument, which you can pass to the
on_extract callback)
@return the return code - 0 on success, negative number (< 0) on error.
*/
/*
fn (mut zentry Zip) extract(path string) bool { fn (mut zentry Zip) extract(path string) bool {
if C.access(path.str, 0) == -1 { if C.access(path.str, 0) == -1 {
return false return false
//return error('Cannot open directory for extracting, directory not exists') // return error('Cannot open directory for extracting, directory not exists')
} }
res := C.zip_extract(zentry, path.str, 0, 0) res := C.zip_extract(zentry, path.str, 0, 0)
return res == 0 return res == 0
} }
*/ */
/*
total returns the number of all entries (files and directories) in the zip archive.
@param zip zip archive handler. // total returns the number of all entries (files and directories) in the zip archive.
@return the return code - the number of entries on success, negative number
(< 0) on error.
*/
pub fn (mut zentry Zip) total() ?int { pub fn (mut zentry Zip) total() ?int {
tentry := int(C.zip_total_entries(zentry)) tentry := int(C.zip_total_entries(zentry))
if tentry == -1 { if tentry == -1 {

View File

@ -1,7 +1,7 @@
import szip import szip
import os import os
fn test_compile() { fn test_szip() {
mut z := szip.open('test_compile.zip', szip.best_speed, szip.m_write) or { mut z := szip.open('test_compile.zip', szip.best_speed, szip.m_write) or {
assert false assert false
return return
@ -11,3 +11,4 @@ fn test_compile() {
os.rm('test_compile.zip') or { } os.rm('test_compile.zip') or { }
} }
} }