Extract files through streams

Source: Internet
Author: User

In order to make the code more concise, transfer is directly used to mount the transfer operation of two streams.

// Initialize the file input stream tb_stream_ref_t istream = streams ("/home/file.txt"); // initialize the file output stream tb_stream_ref_t ostream = tb_stream_init_from_file ("/home/file.gz ", tb_file_mode_rw | extract | tb_file_mode_binary | extract); // initialize the extract stream and use istream as the input tb_stream_ref_t fstream = extract (istream, batch, tb_zip_action_inflate, use istream as the input // tb_stream_ref_t fstream = tb_stream_init_filter_from_zip (istream, tb_zip_algo_gzip, tb_zip_action_deflate); // stream transmission, and decompress and compress if (istream & ostream & fstream) through fstream. {/* stores stream data, if every stream has not been opened by calling tb_stream_open * this will automatically enable it for you. In this way, the upper-layer interface is more concise and clear. ** the following three parameters are mainly used: the speed limit and progress information callback are described in detail later. * now you only need to pass null. ** save indicates the actual data size transmitted. If it fails, the following error is returned: -1 */tb_hong_t save = tb_transfer_done (fstream, ostream, 0, tb_null, tb_null);} // release stream data if (fstream) tb_stream_exit (fstream); If (istream) tb_stream_exit (istream); If (ostream) tb_stream_exit (ostream );

 

Extract files through streams

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.