PHP Compression and archive-bzip2

Source: Internet
Author: User
Tags string to file
The BZIP2 function is used to transparently read and write bzip2 (. bz2) Compressed files.

This module uses the functions in the»BZIP2 Library of Julian Seward. This module requires BZIP2/LIBBZIP2 version >= 1.0.x.

PHP BZIP2 support is not turned on by default. Compile PHP requires--with-bz2[=dir] configuration options to activate BZIP2 support.

The following example opens a temporary file and writes a test string, and then outputs the contents of the file:

Example #1 bzip2 Small Example

<?php    $filename = "/tmp/testfile.bz2";    $str = "This is a test string.\n";    Open a file for writing    $bz = Bzopen ($filename, "w");    Write string to file    bzwrite ($BZ, $str);    Close file    bzclose ($BZ);    Open file for reading    $BZ = Bzopen ($filename, "R");    Reads 10 characters    of Echo Bzread ($BZ, ten);    Output until the end of the file (or 1024 characters later), and close.    Echo Bzread ($BZ);    Bzclose ($BZ);? >

Related functions:

bzclose-Close a bzip2 file

bzcompress-to compress a string into BZIP2 encoded data

bzdecompress-extracting data encoded by BZIP2

bzerrno-returns a bzip2 error code

bzerror-returns an array containing the BZIP2 error number and the error string

bzerrstr-returns an bzip2 error string

bzflush-Force write data to all write buffers

bzopen-open a file that has been bzip2 compressed

BZREAD-BZIP2 file binary securely read

bzwrite-binary securely writes bzip2 files

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.