bzip2 压缩包操作类¶
属性 | 值 |
---|---|
命名空间 | fize\misc |
类名 | Bz2 |
方法: |
---|
方法名 | 说明 |
---|---|
__construct() | 构造 |
__destruct() | 析构函数 |
close() | 关闭 bzip2 文件 |
compress() | 把一个字符串压缩成 bzip2 编码数据 |
decompress() | 解压经 bzip2 编码过的数据 |
errno() | 返回一个 bzip2 错误码 |
error() | 返回包含 bzip2 错误号和错误字符串的一个数组 |
errstr() | 返回一个 bzip2 的错误字符串 |
flush() | 强制写入所有写缓冲区的数据 |
open() | 打开一个经 bzip2 压缩过的文件 |
read() | 从文件读取数据 |
write() | 二进制安全地写入 bzip2 文件 |
方法¶
__construct()¶
构造
public function __construct (
string $file,
string $mode
)
参数: |
|
---|
参数 `$file` :
指定文件不存在时将尝试创建
参数 `$mode` :
和 fopen() 函数类似,但仅仅支持 'r'(读)和 'w'(写)。
compress()¶
把一个字符串压缩成 bzip2 编码数据
public static function compress (
string $source,
int $blocksize = 4,
int $workfactor = 0
) : string
参数: |
|
||||||||
---|---|---|---|---|---|---|---|---|---|
返回值: | 压缩后的字符串 |
参数 `$blocksize` :
应该是一个 1-9 的数字。9 可以有最高的压缩比,但会使用更多的资源。
参数 `$workfactor` :
值可以是在 0 至 250 之间,0 是一个特殊的情况。
decompress()¶
解压经 bzip2 编码过的数据
public static function decompress (
string $source,
int $small = 0
) : string
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 解压后的字符串 |
open()¶
打开一个经 bzip2 压缩过的文件
public function open (
string $file,
string $mode
)
参数: |
|
---|
参数 `$mode` :
和 `fopen()` 函数类似,但仅仅支持 'r'(读)和 'w'(写)。
其他任何模式都会导致 bzopen 返回 FALSE。
read()¶
从文件读取数据
public function read (
int $length = 1024
) : string
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 返回解压的数据 |
参数 `$length` :
读取到 length(未经压缩的长度)个字节,或者到文件尾,取决于先到哪个。
如果没有提供该参数, read() 方法一次会读入 1024 个字节(未经压缩的长度)。
一次最大可读入 8192 个未压缩的字节。
write()¶
二进制安全地写入 bzip2 文件
public function write (
string $data,
int $length = null
) : int
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 返回写入的数据字节数 |
注意不能多次调用该方法,bz2文件是一次性写入并覆盖的
参数 `$length` :
如果提供了参数 `$length` ,将仅仅写入 length(未压缩)个字节,
若 data 小于该指定的长度则写入全部数据。