From f53ed664333311811d185d08deeb6809e6362a8f Mon Sep 17 00:00:00 2001
From: Paul <pmqs@cpan.org>
Date: Fri, 26 Sep 2014 23:44:43 +0100
Subject: Fix gunzip to in-memory file handle

Bug: https://rt.cpan.org/Public/Bug/Display.html?id=95494
Bug-Debian: http://bugs.debian.org/747363
Patch-Name: fixes/io_uncompress_gunzip_inmemory.diff
---
 cpan/IO-Compress/lib/IO/Uncompress/Base.pm |  3 ++-
 cpan/IO-Compress/t/compress/oneshot.pl     | 27 +++++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/cpan/IO-Compress/lib/IO/Uncompress/Base.pm b/cpan/IO-Compress/lib/IO/Uncompress/Base.pm
index 4d1b780285..c3ff842e78 100644
--- a/cpan/IO-Compress/lib/IO/Uncompress/Base.pm
+++ b/cpan/IO-Compress/lib/IO/Uncompress/Base.pm
@@ -756,7 +756,8 @@ sub _rd2
 
         while (($status = $z->read($x->{buff})) > 0) {
             if ($fh) {
-                syswrite $fh, ${ $x->{buff} }
+                local $\;
+                print $fh ${ $x->{buff} }
                     or return $z->saveErrorString(undef, "Error writing to output file: $!", $!);
                 ${ $x->{buff} } = '' ;
             }
diff --git a/cpan/IO-Compress/t/compress/oneshot.pl b/cpan/IO-Compress/t/compress/oneshot.pl
index 1e56b56725..43d9c02f64 100644
--- a/cpan/IO-Compress/t/compress/oneshot.pl
+++ b/cpan/IO-Compress/t/compress/oneshot.pl
@@ -16,7 +16,7 @@ BEGIN {
     $extra = 1
         if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
 
-    plan tests => 995 + $extra ;
+    plan tests => 1002 + $extra ;
 
     use_ok('IO::Uncompress::AnyUncompress', qw(anyuncompress $AnyUncompressError)) ;
 
@@ -1583,7 +1583,7 @@ sub run
 
 
     {
-        # check setting $/ 
+        # check setting $\ 
 
         my $CompFunc = getTopFuncRef($CompressClass);
         my $UncompFunc = getTopFuncRef($UncompressClass);
@@ -1600,7 +1600,30 @@ sub run
 
     }
 
+    SKIP:
+    {
+        #95494: IO::Uncompress::Gunzip: Can no longer gunzip to in-memory file handle
+
+        skip "open filehandle to buffer not supported in Perl $]", 7
+            if $] < 5.008 ;
+        my $CompFunc = getTopFuncRef($CompressClass);
+        my $UncompFunc = getTopFuncRef($UncompressClass);
+
+        my $input = "hello world";
+        my $compressed ;
+        ok open my $fh_in1, '<', \$input ;
+        ok open my $fh_out1, '>', \$compressed ;
+        ok &$CompFunc($fh_in1 => $fh_out1), '  Compressed ok' ;
+
+        my $output;
+        ok open my $fh_in2, '<', \$compressed ;
+        ok open my $fh_out2, '>', \$output ;
+
+        ok &$UncompFunc($fh_in2 => $fh_out2), '  UnCompressed ok' ;
+        is $output, $input, "round trip ok" ;
+    }
 }
+
 # TODO add more error cases
 
 1;
