Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

PerlIO::via::xz

by Tux (Abbot)
on Oct 02, 2020 at 15:43 UTC ( #11122482=perlmeditation: print w/replies, xml ) Need Help??

There are streaming modules on CPAN that support gzip and Bzip2 and many more based on PerlIO::via, all using syntax like:

# compress open my $fh, ">:via(XXZ)", "test.xxz"; print $fh $text; # decompress open my $fh, "<:via(XXZ)", "test.xxz"; while (<$fh>) { ... }

where XXZ is the required PerlIO::via::XXZ (gzip, Bzip2, ...) and .xxz is the extension that goes with it (.gz, .bz2, ...).

I needed this for xz-(de)compression, but it wasn't there (yet), so I stole from existing modules and whipped up PerlIO::via::xz, which works for what I want.

BUT, it fails in a scope where $/ = undef;, and I have no tuits to investigate.

This has not (yet) been put to CPAN, and to be honest, I don't feel like it (yet).

If anyone thinks this is a good thing to have and wants a kickstart in getting something ready to distribute, please contact me: you're welcome to grab it a use it to make it *your* (first) distribution.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re: PerlIO::via::xz
by choroba (Archbishop) on Oct 03, 2020 at 19:49 UTC
    Good idea. I learned about xz several weeks ago at work.

    I tried to fork your repo on GitHub and ran prove -vl. There were no test failures. Even running

    perl -Ilib sandbox/xz-undef.pl
    doesn't show any problems.

    What do you mean by "it fails"?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Change $/ = "\xff\xfe\xff\xfe" x 16 to undef in t/10-xz.t. (trice).

      sandbox/xz-undef.pl shows it is not the underlying IO modules to blame.

      $ perl -Mblib -MPerlIO::via::xz -wE'open my $fh, "<:via(xz)", "files/p +lain.xz";print scalar<$fh>' Lorem ipsum dolor sit amet, consectetur adipiscing elit, $ perl -Mblib -MPerlIO::via::xz -wE'open my $fh, "<:via(xz)", "files/p +lain.xz";$/=undef;print scalar<$fh>'

      or replace t/10-xz.t with this:


      Enjoy, Have FUN! H.Merijn
        I tried to debug it, the reading happens at IO::Uncompress::Base line 73. $$out is not populated. I'm at my wits' end.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: PerlIO::via::xz
by choroba (Archbishop) on Nov 05, 2020 at 09:25 UTC
    Solved!

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://11122482]
Approved by Athanasius
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2020-11-28 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?