chiark / gitweb /
Actually compress marketdata.gz (!)
[ypp-sc-tools.main.git] / pctb / commod-results-processor
index 4a70ddf7767376ab8b9db5406750c257460e9c3c..fe26f8847348aea3dbaf7e076f05b2ef52269744 100755 (executable)
@@ -435,6 +435,24 @@ sub save_upload_html ($$) {
     close R or die $!;
 }
 
+sub gzip ($) {
+    my ($raw) = @_;
+    my $tf= IO::File::new_tmpfile() or die $!;
+    print $tf $raw or die $!;
+    $tf->flush or die $!;
+    $tf->seek(0,0) or die $!;
+    my $child= open GZ, "-|"; defined $child or die $!;
+    if (!$child) {
+       open STDIN, "<&", $tf;
+       exec 'gzip'; die $!;
+    }
+    my $r;
+    { undef $/; $!=0; $r= <GZ>; }
+    defined $r or die $!;
+    close GZ or die "$! $?";  die $? if $?;
+    return $r;
+}
+
 sub main__upload () {
     my $ocean= $ENV{'YPPSC_OCEAN'};  die unless $ocean;
     my $island= $ENV{'YPPSC_ISLAND'};  die unless $island;
@@ -445,7 +463,7 @@ sub main__upload () {
     my $content= {
        'marketdata' => [ undef, "marketdata.gz",
                          Content_Type => 'application/gzip',
-                         Content => $o
+                         Content => gzip($o),
                          ]
                      };