Rand Stats

IO::Path::AutoDecompress

zef:lizmat

Actions Status Actions Status Actions Status

NAME

IO::Path::AutoDecompress - IO::Path with automatic decompression

SYNOPSIS

use IO::Path::AutoDecompress;

# read lines from a gzipped file transparently
my $io = IO::Path::AutoDecompress.new("foobar.txt.gz");
.say for $io.lines;

# same, but using an .IO like subroutine as a method
my $io = "foobar.txt.gz".&IOAD;
.say for $io.lines;

DESCRIPTION

IO::Path::AutoDecompress is a distribution that provides a subclass to IO::Path, that will transparently handle compressed files that are compressed with gzip (the .gz file extension) or bzip2 (the .bz2 extension) for the .slurp and .lines methods.

EXPORTED SUBROUTINES

IOAD

The IOAD subroutine takes one positional argument and converts that to an IO::Path::AutoDecompress object. It is intended to be used in a way similar to the .IO method in core.

use IO::Path::AutoDecompress;

# using the IOAD subroutine as a method
my $io = "foobar.txt.gz".&IOAD;
.say for $io.lines;

PREREQUISITES

This module assumes some version of the gunzip and bunzip2 programs can be executed with the --stdout argument. Most Unixes and derivatives come installed with those.

Alternately the 7z program can be used. This can be installed thusly:

For Debian-based Linux distributions, such as Ubuntu or Debian, you can install 7zip using the apt package manager

sudo apt update
sudo apt install p7zip-full
Red Hat/Fedora/CentOS Systems

For Fedora, CentOS, and other RPM-based distributions, use the following command:

sudo dnf install p7zip

For older CentOS/RHEL systems with yum:

sudo yum install p7zip

For Arch Linux and other Arch-based distributions, use the following command:

sudo pacman -S p7zip

For MacOS, install using brew:

brew install p7zip

For Windows, use the download page of 7-Zip itself.

AUTHOR

Elizabeth Mattijsen liz@raku.rocks

Source can be located at: https://github.com/lizmat/IO-Path-AutoDecompress . Comments and Pull Requests are welcome.

If you like this module, or what I’m doing more generally, committing to a small sponsorship would mean a great deal to me!

COPYRIGHT AND LICENSE

Copyright 2022, 2024, 2026 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.