How do I read a GZipped UTF-8 file from Perl on Windows?

Discussion in 'Perl Misc' started by DmitryB, May 29, 2007.

  1. DmitryB

    DmitryB Guest

    Hi, folks,

    I'm looking for a way to read and write *.gz text files in UTF8
    encoding on windows (ActivePerl, gzip Perl::IO layer is not
    available). I've tried naive IO::Zlib stuff like this:

    tie *OUTPUTFILE, "IO::Zlib", $outputFile, "wb" or die "Could not open
    $outputFile for reading";
    binmode(OUTPUTFILE, ":utf8");

    Unfortunately this doesn't work, the error is:

    "Not a GLOB reference at c:/bin/perl/lib/IO/Zlib.pm line 566."


    Basically, the goal is to layer utf8 on top of zlib or achieve a
    similar result using other means. Again, keep in mind, I can't just
    say "gzip" in open() because that's not available.

    Does anyone have any pointers?

    Thanks.
     
    DmitryB, May 29, 2007
    #1
    1. Advertising

  2. DmitryB

    DmitryB Guest

    On May 29, 1:24 pm, DmitryB <> wrote:
    > Hi, folks,
    >
    > I'm looking for a way to read and write *.gz text files in UTF8
    > encoding on windows (ActivePerl, gzip Perl::IO layer is not
    > available). I've tried naive IO::Zlib stuff like this:
    >
    > tie *OUTPUTFILE, "IO::Zlib", $outputFile, "wb" or die "Could not open
    > $outputFile for reading";
    > binmode(OUTPUTFILE, ":utf8");
    >
    > Unfortunately this doesn't work, the error is:
    >
    > "Not a GLOB reference at c:/bin/perl/lib/IO/Zlib.pm line 566."
    >
    > Basically, the goal is to layer utf8 on top of zlib or achieve a
    > similar result using other means. Again, keep in mind, I can't just
    > say "gzip" in open() because that's not available.
    >
    > Does anyone have any pointers?
    >
    > Thanks.


    I just ended up using out of process piped gzip. Works pretty good if
    you don't forget to quote the filename. :)
     
    DmitryB, Jun 1, 2007
    #2
    1. Advertising

  3. On Fri, 01 Jun 2007 05:47:13 -0000, DmitryB <>
    wrote:

    >I just ended up using out of process piped gzip. Works pretty good if
    >you don't forget to quote the filename. :)


    Hard to say without seeing any code, but I suspect you're using
    something like

    open my $fh, '-|', 'gzip -d "filename.gz"' or die $!;

    In that case, you can also give the arguments to gzip in LIST form as

    open my $fh, '-|', 'gzip' => '-d', 'filename.gz' or die $!;

    which may be useful.


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Jun 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Smith

    Can sqlite read gzipped databases?

    Paul Smith, Mar 21, 2007, in forum: Python
    Replies:
    1
    Views:
    985
    John Nagle
    Mar 21, 2007
  2. John Nagle
    Replies:
    1
    Views:
    606
    Martin v. Löwis
    Nov 22, 2007
  3. moonhkt
    Replies:
    18
    Views:
    2,608
    Roedy Green
    Feb 5, 2010
  4. Guido de Melo

    trouble reading a gzipped xml-file

    Guido de Melo, Nov 14, 2005, in forum: Ruby
    Replies:
    4
    Views:
    154
    Guido de Melo
    Nov 14, 2005
  5. Replies:
    0
    Views:
    985
Loading...

Share This Page