]> iEval git - slob.git/commitdiff
Add bz2 and zlib support
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 6 Jan 2018 18:06:47 +0000 (20:06 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 6 Jan 2018 18:06:47 +0000 (20:06 +0200)
MANIFEST
Makefile.PL
lib/Slob.pm
t/Slob.t
t/freedict-bz2.slob [new file with mode: 0644]
t/freedict-zlib.slob [new file with mode: 0644]

index 48b0971483f02cd47b8e6c5fd4cc6b9327852703..c54d7da79d4de8adfea04715883fb3dd1fcfef03 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4,5 +4,7 @@ MANIFEST
 README
 t/Slob.t
 t/freedict-uncompressed.slob
+t/freedict-bz2.slob
 t/freedict-lzma2.slob
+t/freedict-zlib.slob
 lib/Slob.pm
index 317d6c4f8a584f3bee000e7add29004e6914acc5..5688370e815ebf030f957e1f0aa9fb272c245ca5 100644 (file)
@@ -14,7 +14,9 @@ WriteMakefile(
        LICENSE           => 'perl',
        SIGN              => 1,
        PREREQ_PM         => {
-               qw/Compress::Raw::Lzma 0/,
+               qw/Compress::Raw::Bzip2 0
+                  Compress::Raw::Lzma  0
+                  Compress::Raw::Zlib  0/,
        },
        META_ADD          => {
                dynamic_config => 0,
index b64664f1fcc016e32b73643d33d0de723b1876af..3e9697fff3c7c2faea0550ea579f1f4bc6848a33 100644 (file)
@@ -10,7 +10,9 @@ use constant MAGIC => "!-1SLOB\x1F";
 use Carp qw/croak verbose/;
 use Encode;
 
+use Compress::Raw::Bzip2;
 use Compress::Raw::Lzma;
+use Compress::Raw::Zlib;
 
 our %UNCOMPRESS = (
        '' => sub { $_[0] },
@@ -19,9 +21,37 @@ our %UNCOMPRESS = (
                my ($lzma2, $code, $output);
                ($lzma2, $code) = Compress::Raw::Lzma::RawDecoder->new(Filter => Lzma::Filter::Lzma2());
                die "Error creating LZMA2 decoder: $code\n" unless $code == LZMA_OK;
+
                $code = $lzma2->code($input, $output);
-               die "Did not reach end of stream" if $code == LZMA_OK;
-               die "Error decoding LZMA2: $code" if $code != LZMA_STREAM_END;
+               die "Did not reach end of stream\n" if $code == LZMA_OK;
+               die "Error decoding LZMA2: $code\n" if $code != LZMA_STREAM_END;
+               $output
+       },
+
+       'bz2' => sub {
+               my ($input) = @_;
+               my ($bz2, $code, $output);
+               ($bz2, $code)= Compress::Raw::Bunzip2->new;
+               die "Error creating Bunzip2: $code\n" unless $code == Z_OK;
+
+               $code = $bz2->bzinflate($input, $output);
+               die "Did not reach end of stream\n" if $code == BZ_OK;
+               die "Error decoding Bzip2: $code\n" if $code != BZ_STREAM_END;
+
+               $output
+       },
+
+       'zlib' => sub {
+               my ($input) = @_;
+               my ($zlib, $code, $output);
+               ($zlib, $code) = Compress::Raw::Zlib::Inflate->new(
+                       -WindowBits => WANT_GZIP_OR_ZLIB
+               );
+               die "Error creating Zlib inflate: $code\n" unless $code == Z_OK;
+
+               $code = $zlib->inflate($input, \$output, 1);
+               die "Did not reach end of stream\n" if $code == Z_OK;
+               die "Error inflating zlib: $code\n" if $code != Z_STREAM_END;
                $output
        }
 );
index ef2aa21bf2bfef5117bc6ab38ad03850b76a05b9..70bc6e2a3399162f1a2de504ffc4ebb9dfdd45a0 100644 (file)
--- a/t/Slob.t
+++ b/t/Slob.t
@@ -2,11 +2,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 13;
+use Test::More tests => 25;
 BEGIN { use_ok('Slob') };
 
-for my $path (qw/freedict-uncompressed.slob freedict-lzma2.slob/) {
-       my $slob = Slob->new("t/$path");
+for my $path (<t/freedict-*.slob>) {
+       note "Now using $path";
+       my $slob = Slob->new($path);
 
        my $nr_of_entries = $slob->ref_count;
 
diff --git a/t/freedict-bz2.slob b/t/freedict-bz2.slob
new file mode 100644 (file)
index 0000000..ec77322
Binary files /dev/null and b/t/freedict-bz2.slob differ
diff --git a/t/freedict-zlib.slob b/t/freedict-zlib.slob
new file mode 100644 (file)
index 0000000..b74dd62
Binary files /dev/null and b/t/freedict-zlib.slob differ
This page took 0.040425 seconds and 4 git commands to generate.