- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP compression Stream Wrappers
In PHP, zlib://, bzip2:// and zip:// represent wrappers for respective compression streams.
This works similar to gzopen() function, however, it can be used with filesystem functions like fread() and others.
This is similar to bzopen() function. Both stream wrappers operate even on systems not capable of supporting fopencookie.
The ZIP extension registers this wrapper. From PHP 7.2.0 onwards, archives encrypted with passwords are supported. It is possible to set password with password context option.
zlib compression can be applied with following PHP code
<?php file_put_contents("compress.zlib://test.txt.gz","Hello World\r\n"); ?>
To uncompress, we can use following syntax
<?php echo file_get_contents("compress.zlib://test.txt.gz"); ?>
We can also use built-in copy() function to build compressed zlib file and uncompress the same
copy('file.txt', 'compress.zlib://' . 'file.txt.gz'); copy('compress.zlib://' . 'file.txt.gz', 'file.txt');
- How To enable GZIP Compression in PHP?
- Difference between Lossy Compression and Lossless Compression
- Enable MySQL Compression
- What is DjVu Compression?
- Data compression in SAP HANA
- Character Stream vs Byte Stream in Java
- Data Compression in SAP HANA system
- Python Support for bzip2 compression (bz2)
- Compression compatible with gzip in Python (zlib)
- Program to perform string compression in Python
- Stream In Java
- What is STREAM?
- Manual compression of a table in SAP HANA
- Compression using the LZMA algorithm using Python (lzma)
- Difference between the byte stream and character stream classes in Java?