Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_get_contents equivalent for gzipped files

Tags:

file

php

gzip

What would be equivalent function to file_get_contents, which reads the whole content of a text file written using gzwrite function?

like image 567
Sfisioza Avatar asked Aug 13 '13 10:08

Sfisioza


People also ask

What is Gzipped file?

gzip is a file format and a software application used for file compression and decompression. The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program used in early Unix systems, and intended for use by GNU (from where the "g" of gzip is derived).

Can you cat Gzipped files?

We can use some common commands like cat and tar to concatenate Gzip files in the Linux system.

What is file_get_contents?

The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance performance.

What does file_get_contents return?

This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to length bytes. On failure, file_get_contents() will return false . file_get_contents() is the preferred way to read the contents of a file into a string.


1 Answers

This is way easier using stream wrappers

file_get_contents('compress.zlib://'.$file);

https://stackoverflow.com/a/8582042/1235815

like image 127
Paul Phillips Avatar answered Oct 21 '22 06:10

Paul Phillips