Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SpringMT committed Apr 11, 2024
1 parent 0a753d2 commit e4d97ab
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ Or install it yourself as:
require 'zstd-ruby'
```

### Simple Compression
### Compression

#### Simple Compression

```ruby
compressed_data = Zstd.compress(data)
compressed_data = Zstd.compress(data, complession_level) # default compression_level is 0
compressed_data = Zstd.compress(data, level: complession_level) # default compression_level is 3
```

### Compression using Dictionary
#### Compression with Dictionary
```ruby
# dictionary is supposed to have been created using `zstd --train`
compressed_using_dict = Zstd.compress_using_dict("", IO.read('dictionary_file'))
compressed_using_dict = Zstd.compress("", dict: IO.read('dictionary_file'))
```

### Streaming Compression
#### Streaming Compression
```ruby
stream = Zstd::StreamingCompress.new
stream << "abc" << "def"
Expand All @@ -66,7 +68,7 @@ res << stream.compress("def")
res << stream.finish
```

### Streaming Compression using Dictionary
#### Streaming Compression with Dictionary
```ruby
stream = Zstd::StreamingCompress.new(dict: IO.read('dictionary_file'))
stream << "abc" << "def"
Expand All @@ -75,19 +77,30 @@ stream << "ghi"
res << stream.finish
```

### Simple Decompression
#### Streaming Compression with level and Dictionary
```ruby
stream = Zstd::StreamingCompress.new(level: 5, dict: IO.read('dictionary_file'))
stream << "abc" << "def"
res = stream.flush
stream << "ghi"
res << stream.finish
```

### Decompression

#### Simple Decompression

```ruby
data = Zstd.decompress(compressed_data)
```

### Decomporession using Dictionary
#### Decompression with Dictionary
```ruby
# dictionary is supposed to have been created using `zstd --train`
Zstd.decompress_using_dict(compressed_using_dict, IO.read('dictionary_file'))
Zstd.decompress(compressed_using_dict, dict: IO.read('dictionary_file'))
```

### Streaming Decompression
#### Streaming Decompression
```ruby
cstr = "" # Compressed data
stream = Zstd::StreamingDecompress.new
Expand All @@ -96,7 +109,7 @@ result << stream.decompress(cstr[0, 10])
result << stream.decompress(cstr[10..-1])
```

### Streaming Decompression using dictionary
#### Streaming Decompression with dictionary
```ruby
cstr = "" # Compressed data
stream = Zstd::StreamingDecompress.new(dict: IO.read('dictionary_file'))
Expand Down

0 comments on commit e4d97ab

Please sign in to comment.