Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/Compress/Zstd.xs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ BOOT:
{
HV* stash = gv_stashpv("Compress::Zstd::Compressor", 1);
newCONSTSUB(stash, "ZSTD_CSTREAM_IN_SIZE", newSViv(ZSTD_CStreamInSize()));
newCONSTSUB(stash, "ZSTD_c_windowLog", newSVuv(ZSTD_c_windowLog));
}

Compress::Zstd::Compressor
Expand Down Expand Up @@ -238,6 +239,17 @@ init(self, level = 1)
CODE:
ZSTD_initCStream(self->stream, level);

void
set_parameter(self, cParam, value)
Compress::Zstd::Compressor self;
unsigned long cParam;
int value;
CODE:
size_t ret = ZSTD_CCtx_setParameter( self->stream, (ZSTD_cParameter)cParam, value );
if (ZSTD_isError(ret)) {
croak("%s", ZSTD_getErrorName(ret));
}

SV*
compress(self, input)
Compress::Zstd::Compressor self;
Expand Down Expand Up @@ -317,6 +329,7 @@ BOOT:
{
HV* stash = gv_stashpv("Compress::Zstd::Decompressor", 1);
newCONSTSUB(stash, "ZSTD_DSTREAM_IN_SIZE", newSViv(ZSTD_DStreamInSize()));
newCONSTSUB(stash, "ZSTD_d_windowLogMax", newSVuv(ZSTD_d_windowLogMax));
}

Compress::Zstd::Decompressor
Expand Down Expand Up @@ -349,6 +362,17 @@ init(self)
CODE:
ZSTD_initDStream(self->stream);

void
set_parameter(self, dParam, value)
Compress::Zstd::Decompressor self;
unsigned long dParam;
int value;
CODE:
size_t ret = ZSTD_DCtx_setParameter( self->stream, (ZSTD_dParameter)dParam, value );
if (ZSTD_isError(ret)) {
croak("%s", ZSTD_getErrorName(ret));
}

SV*
decompress(self, input)
Compress::Zstd::Decompressor self;
Expand Down
16 changes: 16 additions & 0 deletions lib/Compress/Zstd/Compressor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use Compress::Zstd ();

our @EXPORT = qw(
ZSTD_CSTREAM_IN_SIZE
ZSTD_c_windowLog
);

1;
Expand Down Expand Up @@ -55,12 +56,27 @@ Flush whatever data remains within internal buffer.

Instructs to finish a frame.

=head2 $compressor->set_parameter( PARAMETER => VALUE )

Sets one of the compressor’s internal parameters. PARAMETER
is one of the parameter constants listed below.

=head1 CONSTANTS

=head2 ZSTD_CSTREAM_IN_SIZE

Recommended size for input buffer.

=head1 PARAMETER CONSTANTS

The following may be given to C<set_parameter()>:

=over

=item * C<ZSTD_c_windowLog>

=back

=head1 SEE ALSO

L<http://www.zstd.net/>
Expand Down
16 changes: 16 additions & 0 deletions lib/Compress/Zstd/Decompressor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use Compress::Zstd ();

our @EXPORT = qw(
ZSTD_DSTREAM_IN_SIZE
ZSTD_d_windowLogMax
);

1;
Expand Down Expand Up @@ -46,12 +47,27 @@ Create an instance of Compress::Zstd::Decompressor.

Consume input stream.

=head2 $decompressor->set_parameter( PARAMETER => VALUE )

Sets one of the decompressor’s internal parameters. PARAMETER
is one of the parameter constants listed below.

=head1 CONSTANTS

=head2 ZSTD_DSTREAM_IN_SIZE

Recommended size for input buffer.

=head1 PARAMETER CONSTANTS

The following may be given to C<set_parameter()>:

=over

=item * C<ZSTD_d_windowLogMax>

=back

=head1 SEE ALSO

L<Compress::Zstd>
Expand Down
30 changes: 30 additions & 0 deletions t/05_streaming_windowlog.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use strict;
use warnings;

use Test::More;
use Compress::Zstd::Compressor qw(ZSTD_c_windowLog);
use Compress::Zstd::Decompressor qw(ZSTD_d_windowLogMax);

cmp_ok ZSTD_c_windowLog, '>', 0;
cmp_ok ZSTD_d_windowLogMax, '>', 0;

my $compressor = Compress::Zstd::Compressor->new;
$compressor->set_parameter( ZSTD_c_windowLog, 10 );

my $output = '';
$output .= $compressor->compress('a');
$output .= $compressor->compress('b');
$output .= $compressor->compress('c');
$output .= $compressor->flush;
$output .= $compressor->end;
ok $output;

my $decompressor = Compress::Zstd::Decompressor->new;
$decompressor->set_parameter( ZSTD_d_windowLogMax, 10);

my $result = '';
$result .= $decompressor->decompress(substr($output, 0, 3));
$result .= $decompressor->decompress(substr($output, 3, -1));
is $result, 'abc';

done_testing;