Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Oct 21, 2022
1 parent fb4f3de commit 2015f5a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ Revision history for IO-Path-AutoDecompress

{{$NEXT}}

0.0.2 2022-10-21T12:10:08+02:00
- Add IOAD subroutine, for use as alternate .IO
- Add more documentation and examples

0.0.1 2022-10-20T15:45:21+02:00
- Initial version
4 changes: 3 additions & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
],
"source-url": "https://github.com/lizmat/IO-Path-AutoDecompress.git",
"tags": [
"IO",
"COMPRESS"
],
"test-depends": [
],
"version": "0.0.1"
"version": "0.0.2"
}
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,37 @@ SYNOPSIS

```raku
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 module 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.

```raku
use IO::Path::AutoDecompress;

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

PREREQUISITES
=============

Expand Down
30 changes: 30 additions & 0 deletions lib/IO/Path/AutoDecompress.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class IO::Path::AutoDecompress is IO::Path {
}
}

my sub IOAD($path) is export {
IO::Path::AutoDecompress.new($path)
}

=begin pod
=head1 NAME
Expand All @@ -46,6 +50,14 @@ IO::Path::AutoDecompress - IO::Path with automatic decompression
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;
=end code
=head1 DESCRIPTION
Expand All @@ -55,6 +67,24 @@ C<IO::Path>, that will transparently handle compressed files that
are compressed with C<gzip> (the C<.gz> file extension) or C<bzip2>
(the C<.bz2> extension) for the C<.slurp> and C<.lines> methods.
=head1 EXPORTED SUBROUTINES
=head2 IOAD
The C<IOAD> subroutine takes one positional argument and converts
that to an C<IO::Path::AutoDecompress> object. It is intended to
be used in a way similar to the C<.IO> method in core.
=begin code :lang<raku>
use IO::Path::AutoDecompress;
# using the IOAD subroutine as a method
my $io = "foobar.txt.gz".&IOAD;
.say for $io.lines;
=end code
=head1 PREREQUISITES
This module assumes some version of the C<gunzip> and C<bunzip2>
Expand Down
14 changes: 8 additions & 6 deletions t/01-basic.rakutest
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use Test;
use IO::Path::AutoDecompress;

plan 4;
plan 8;

my $path := IO::Path::AutoDecompress.new($*PROGRAM.relative);
my $io := $*PROGRAM;
for IO::Path::AutoDecompress.new($io.relative), $io.&IOAD -> $path {

isa-ok $path, IO::Path::AutoDecompress;
isa-ok $path, IO::Path;
isa-ok $path, IO::Path::AutoDecompress;
isa-ok $path, IO::Path;

is-deeply $path.slurp, $*PROGRAM.slurp, 'normal .slurp ok';
is-deeply $path.lines, $*PROGRAM.lines, 'normal .lines ok';
is-deeply $path.slurp, $io.slurp, 'normal .slurp ok';
is-deeply $path.lines, $io.lines, 'normal .lines ok';
}

# vim: expandtab shiftwidth=4

0 comments on commit 2015f5a

Please sign in to comment.