Skip to content

Commit 63940ba

Browse files
committed
Add zstd_version
1 parent ce8fa99 commit 63940ba

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)
66

77
See https://github.com/facebook/zstd
88

9-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zstd-ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
10-
119
## Zstd version
1210
v1.1.2 (https://github.com/facebook/zstd/releases/tag/v1.1.2)
1311

@@ -29,6 +27,22 @@ Or install it yourself as:
2927

3028
## Usage
3129

30+
```
31+
require 'zstd-ruby'
32+
```
33+
34+
### compression
35+
36+
```
37+
Zstd.compress(data)
38+
```
39+
40+
41+
### decompression
42+
43+
```
44+
Zstd.decompress(compressed_data)
45+
```
3246

3347
## Development
3448

ext/zstdruby/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "mkmf"
22

3-
$CFLAGS = '-I. -O3 -std=c99 -pedantic'
3+
$CFLAGS = '-I. -O3 -std=c99'
44

55
Dir.chdir File.expand_path('..', __FILE__) do
66
$srcs = Dir['**/*.c']

ext/zstdruby/zstdruby.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "zstdruby.h"
22
#include "./libzstd/zstd.h"
33

4+
static VALUE zstdVersion(VALUE self)
5+
{
6+
unsigned version = ZSTD_versionNumber();
7+
return INT2NUM(version);
8+
}
49

510
static VALUE compress(int argc, VALUE *argv, VALUE self)
611
{
@@ -27,7 +32,7 @@ static VALUE compress(int argc, VALUE *argv, VALUE self)
2732
char* output_data = RSTRING_PTR(output);
2833

2934
size_t compressed_size = ZSTD_compress((void*)output_data, max_compressed_size,
30-
(const void*)input_data, input_size, 1);
35+
(const void*)input_data, input_size, compression_level_value);
3136

3237
if (ZSTD_isError(compressed_size)) {
3338
rb_raise(rb_eRuntimeError, "%s: %s", "compress failed", ZSTD_getErrorName(compressed_size));
@@ -106,6 +111,7 @@ void
106111
Init_zstdruby(void)
107112
{
108113
rb_mZstd = rb_define_module("Zstd");
114+
rb_define_module_function(rb_mZstd, "zstd_version", zstdVersion, 0);
109115
rb_define_module_function(rb_mZstd, "compress", compress, -1);
110116
rb_define_module_function(rb_mZstd, "decompress", decompress, 1);
111117
}

spec/zstd-ruby_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
expect(Zstd::VERSION).not_to be nil
77
end
88

9+
describe 'zstd_version' do
10+
it 'should work' do
11+
expect(Zstd.zstd_version).to eq(10102)
12+
end
13+
end
14+
915
describe 'compress' do
1016
it 'should work' do
1117
compressed = Zstd.compress('abc')

zstd-ruby.gemspec

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ Gem::Specification.new do |spec|
2626
spec.files = `git ls-files -z`.split("\x0").reject do |f|
2727
f.match(%r{^(test|spec|features)/})
2828
end
29-
spec.files += ["zstd/lib/zstd.h"]
3029
spec.bindir = "exe"
3130
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
3231
spec.require_paths = ["lib"]
33-
#spec.extensions = ["ext/zstdruby/extconf.rb"]
3432

3533
spec.add_development_dependency "bundler", "~> 1.14"
3634
spec.add_development_dependency "rake", "~> 10.0"

0 commit comments

Comments
 (0)