XU XUv0.8.8
中文

API

#compress/gzip

import: #compress/gzip

counts: 4 fns, 11 methods, 3 types, 5 consts, 0 ifaces

gzip Reader/Writer with CRC-32.

struct Reader

XuAPI
pub struct Reader {
    pub data string
    pub sticky string
}

Purpose

Public struct `Reader`.

Parameters

data string
data
sticky string
field (string)

struct Header

XuAPI
pub struct Header {
    pub mtime int
    pub name string
    pub comment string
    pub os int
}

Purpose

Public struct `Header`.

Parameters

mtime int
field (int)
name string
name
comment string
field (string)
os int
field (int)

struct Writer

XuAPI
pub struct Writer {
    pub buf string
    pub out string
    pub closed bool
    pub name string
    pub comment string
    pub mtime int
    pub os int
}

Purpose

Public struct `Writer`.

Parameters

buf string
buffer
out string
field (string)
closed bool
field (bool)
name string
name
comment string
field (string)
mtime int
field (int)
os int
field (int)

const os_fat

XuAPI
pub const os_fat = 0

Purpose

RFC 1952 OS byte. host_os maps xu_target_os: Windows FAT/Win32=0, macOS/Linux Unix=3, other=255. gzip writes 255 by default; Xu records the compile target so archives are platform-honest. Value `0`.

Parameters

none

const os_unix

XuAPI
pub const os_unix = 3

Purpose

Public constant `os_unix`. Value `3`.

Parameters

none

const os_macintosh

XuAPI
pub const os_macintosh = 7

Purpose

Public constant `os_macintosh`. Value `7`.

Parameters

none

const os_ntfs

XuAPI
pub const os_ntfs = 11

Purpose

Public constant `os_ntfs`. Value `11`.

Parameters

none

const os_unknown

XuAPI
pub const os_unknown = 255

Purpose

Public constant `os_unknown`. Value `255`.

Parameters

none

host_os

XuAPI
pub fn host_os() int

Purpose

Host os.

Parameters

none

Returns

int — a value of this type

new_reader

XuAPI
pub fn new_reader(data string) Reader

Purpose

Construct reader.

Parameters

data string
data (string)

Returns

Reader — a value of this type

new_writer

XuAPI
pub fn new_writer() Writer

Purpose

Construct writer.

Parameters

none

Returns

Writer — a value of this type

(&mut Writer) set_name

XuAPI
pub fn (w &mut Writer) set_name(n string)

Purpose

Method on `&mut Writer`: set name.

Parameters

w &mut Writer
receiver &mut Writer (exclusive borrow)
n string
count, length, or limit (string)

(&mut Writer) set_comment

XuAPI
pub fn (w &mut Writer) set_comment(s string)

Purpose

Method on `&mut Writer`: set comment.

Parameters

w &mut Writer
receiver &mut Writer (exclusive borrow)
s string
source string (string)

(&mut Writer) set_mtime

XuAPI
pub fn (w &mut Writer) set_mtime(sec int)

Purpose

Method on `&mut Writer`: set mtime.

Parameters

w &mut Writer
receiver &mut Writer (exclusive borrow)
sec int
sec (int)

(&mut Writer) set_os

XuAPI
pub fn (w &mut Writer) set_os(id int)

Purpose

Method on `&mut Writer`: set os.

Parameters

w &mut Writer
receiver &mut Writer (exclusive borrow)
id int
id (int)

(&Reader) header

XuAPI
pub fn (r &Reader) header() Header

Purpose

Call `header` on `&Reader`. Throws on failure.

Parameters

r &Reader
receiver &Reader (borrow)

Returns

Header — a value of this type

(&mut Reader) read_all

XuAPI
pub fn (r &mut Reader) read_all() string

Purpose

Method on `&mut Reader`: read all. Throws on failure.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)

Returns

string — result string

(&mut Writer) write

XuAPI
pub fn (w &mut Writer) write(data &string) int

Purpose

Method on `&mut Writer`: write data and return the byte count. Throws on failure.

Parameters

w &mut Writer
receiver &mut Writer (exclusive borrow)
data &string
data (borrowed; caller keeps it; type &string)

Returns

int — bytes written

(&mut Writer) write_string

XuAPI
pub fn (w &mut Writer) write_string(s string) int

Purpose

Method on `&mut Writer`: write a string and return the byte count.

Parameters

w &mut Writer
receiver &mut Writer (exclusive borrow)
s string
source string (string)

Returns

int — bytes written

(&mut Writer) close

XuAPI
pub fn (w &mut Writer) close() int

Purpose

Method on `&mut Writer`: close the resource.

Parameters

w &mut Writer
receiver &mut Writer (exclusive borrow)

Returns

int — a value of this type

(&Writer) bytes

XuAPI
pub fn (w &Writer) bytes() string

Purpose

Method on `&Writer`: return the buffered bytes.

Parameters

w &Writer
receiver &Writer (borrow)

Returns

string — result string

(&Writer) text

XuAPI
pub fn (w &Writer) text() string

Purpose

Method on `&Writer`: return the current text.

Parameters

w &Writer
receiver &Writer (borrow)

Returns

string — result string

copy_stream

XuAPI
pub fn copy_stream#W:StreamWriter,R:StreamReader(dst &mut W, src &mut R) int

Purpose

Emit a gzip member directly to dst using legal non-final stored deflate blocks, then an empty final block and CRC32/ISIZE trailer. No input or output is accumulated. Returns the uncompressed byte count and closes neither endpoint. Failed copies leave an incomplete member; discard it, don't retry. Throws on failure.

Parameters

dst &mut W
destination (exclusive borrow; type &mut W)
src &mut R
source (exclusive borrow; type &mut R)

Returns

int — a value of this type