gzip

Compresses files individually into gzip files.

Category: Programming > Files and Folders

Syntax

gzip(files)

Writes a .gz file next to each input file.

gzip(files, outputfolder)

Writes the results into outputfolder.

names = gzip(___)

Also returns the names of the created files.

Description

Each input file becomes its own <name>.gz file; gzip does not bundle several files into one archive (use zip or tar for that). The originals are kept. Text files typically shrink a lot, binary and already compressed files little.

Use gunzip to restore.

Input arguments

files
File name, wildcard pattern or cell array of names.
outputfolder
Destination folder; created if missing.

Output arguments

names
Cell array with the names of the .gz files.

Example

Compressing a file

writelines(repmat("hello", 100, 1), 'big.txt');
names = gzip('big.txt')
d = dir('big.txt*');
d(2).bytes < d(1).bytes
Output
names = 1×1 cell

    {'big.txt.gz'}
ans = logical
   1

See also

gunzip zip tar untar