Create a Zip Stream from Standard Input with streamzip
You will finish with a repeatable pipeline that turns standard input into a Zip archive, gives its single member a useful name, and verifies the result with unzip. This guide uses the streamzip 1.00 command supplied by Perl 5.38.2 on this machine. Allow about ten minutes. You need a shell, the Perl package that provides streamzip, and the Info-ZIP unzip command for the checks.
The route
Jump straight to the step you need, or tick off Done means at the end.
Everything here runs as an ordinary user. The examples create files in the current directory or in /tmp; they do not need sudo, change services, or alter the input source.
1. Confirm the command and its version
Check which executable the shell will run, then ask it for its version:
$ command -v streamzip
/usr/bin/streamzip
$ streamzip -version
1.00
The version output is useful when a script or an incident report needs to explain which option set was tested. The installed package is Perl 5.38.2-3.2ubuntu0.6. Do not confuse the command version with a Zip archive version: -version reports streamzip itself.
Checkpoint: if command -v returns nothing, stop here and install or enable the package through your normal system administration process. Do not compensate by downloading an unrelated copy into a shared path.
2. Stream input to standard output
By default, streamzip reads standard input and writes a streamed Zip file to standard output. Redirect that binary output to a file:
$ printf '%s\n' 'hello from streamzip' | streamzip > greeting.zip
$ unzip -l greeting.zip
Archive: greeting.zip
Length Date Time Name
--------- ---------- ----- ----
21 ... -
--------- -------
21 1 file
The date and time vary, so the significant parts of the listing are the member name - and the one-file count. A member name of - is the documented default when you do not provide one. The archive is streamed because standard output cannot be assumed to be seekable.
Verify the actual member data without extracting it:
$ unzip -p greeting.zip -
hello from streamzip
That last argument is the Zip member name, not a filename on disk. If the pipeline fails before producing a complete archive, treat the redirected file as incomplete and recreate it rather than relying on it.
3. Give the member a useful name
A streamed archive can still contain a meaningful member name. Pass -member-name before redirecting the output:
$ printf '%s\n' 'daily report' \
| streamzip -member-name report.txt > report.zip
$ unzip -l report.zip
Archive: report.zip
Length Date Time Name
--------- ---------- ----- ----
13 ... report.txt
--------- -------
13 1 file
The name belongs inside the archive. It does not decide where report.zip is written. Keep it as a relative, descriptive filename such as report.txt or data.ndjson, especially when another system will extract it. Do not put secrets or user-controlled path components into an archive name without first applying your application's path policy.
Checkpoint: confirm both layers separately. report.zip is the output file outside the archive; report.txt is the entry inside it.
4. Choose between streamed and ordinary output
If the consumer needs a live stream, standard output is the simple form:
$ producer | streamzip -member-name payload.bin | consumer
No temporary file is created by streamzip itself. This is useful when a pipeline or a network response cannot seek backwards. The receiving program must understand streamed Zip data. Most Zip readers do, but test the actual consumer if interoperability matters.
If you can write directly to disk, use -zipfile:
$ printf '%s\n' 'disk-backed archive' \
| streamzip -zipfile archive.zip -member-name message.txt
$ unzip -p archive.zip message.txt
disk-backed archive
With -zipfile, the default is a non-streamed archive, which is generally the safer choice for programs that expect a conventional file. Add -stream only when you specifically need streamed output while writing to the named file:
$ printf '%s\n' 'forced stream' \
| streamzip -zipfile streamed.zip -stream -member-name message.txt
$ unzip -t streamed.zip
Archive: streamed.zip
testing: message.txt OK
No errors detected in compressed data of streamed.zip.
Warning: -zipfile=F writes the archive to the named path. Check the path before running a pipeline, because an existing file may be replaced. To undo an example safely, remove only the archive you intentionally created, such as archive.zip; do not use a broad wildcard in a directory containing other work.
5. Select compression and size features
The default method is Deflate at level 6. For a deliberately uncompressed entry, use -method store:
$ printf '%s\n' 'already compressed or tiny' \
| streamzip -method store -zipfile stored.zip
$ unzip -lv stored.zip
Archive: stored.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------ ---- -------- ---- -------- -
... Stored ... 0% ... -
For Deflate, the numeric options -0 through -9 select the compression level. -0 means no compression and -9 requests the maximum level; the default is 6. Those switches are ignored when you choose another method. A higher level can cost CPU time without producing a smaller result, so measure with representative input instead of assuming that 9 is always better.
The manpage lists store, deflate, bzip2, lzma, xz, and zstd. LZMA and Zstandard support need their corresponding Perl compression modules installed. Confirm availability on the target machine before selecting either method:
$ streamzip -help | sed -n '1,35p'
Use -zip64 when the input is greater than 4 GiB or when your workflow requires a Zip64-compliant container. It is disabled by default. This option changes archive format compatibility, so check that the downstream reader supports Zip64 before relying on it.
6. Keep scripts honest about failures
Do not pipe blindly into a later step and assume that a file exists just because a path was created. Capture the producer and archive status according to your shell's error-handling policy, then test the finished archive:
set -o pipefail
printf '%s\n' 'checked payload' \
| streamzip -member-name payload.txt > checked.zip
status=$?
if [ "$status" -ne 0 ]; then
printf 'streamzip failed with status %s\n' "$status" >&2
exit "$status"
fi
unzip -t checked.zip
This makes a failed compression step visible to the script. It does not validate the meaning of the input, protect an archive with encryption, or prove that the consumer will accept every Zip feature. Those are separate requirements. For sensitive data, remember that streamzip creates a Zip container but does not provide password protection.
Done means
streamzip -versionreports the expected installed command.- A pipeline writes valid Zip output and
unzip -torunzip -lverifies it. - The archive member has an intentional name instead of the default
-where that matters. - You chose standard-output streaming or
-zipfiledisk output deliberately. - Compression method, level, Zip64, and downstream reader support match the real workload.
- Your script checks the command result before handing the archive to another process.