From 3cdb57b58c2b98fe26abd95294cdc95d596dc935 Mon Sep 17 00:00:00 2001 From: SpringMT Date: Fri, 26 Apr 2024 15:37:10 +0900 Subject: [PATCH] feat: add "zstd-ruby/stream_writer" and "zstd-ruby/stream_reader" loading Add documents for Zstd::StreamWriter and Zstd::StreamReader --- README.md | 39 ++++++++++++++++++++++++++++ lib/zstd-ruby.rb | 2 ++ spec/zstd-ruby-stream_reader_spec.rb | 2 -- spec/zstd-ruby-stream_writer_spec.rb | 1 - 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 141eeb2..5c8c6ec 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,45 @@ Zstd.read_skippable_frame(compressed_data_with_skippable_frame) # => "sample data" ``` +### Stream Writer and Reader Wrapper +** EXPERIMENTAL * + +* These features are experimental and may be subject to API changes in future releases. +* There may be performance and compatibility issues, so extensive testing is required before production use. +* If you have any questions, encounter bugs, or have suggestions, please report them via [GitHub issues](https://github.com/SpringMT/zstd-ruby/issues). + +#### Zstd::StreamWriter + +``` +require 'stringio' +require 'zstd-ruby' + +io = StringIO.new +stream = Zstd::StreamWriter.new(io) +stream.write("abc") +stream.finish + +io.rewind +# Retrieve the compressed data +compressed_data = io.read +``` + +#### Zstd::StreamReader + +``` +require 'stringio' +require 'zstd-ruby' # Add the appropriate require statement if necessary + +io = StringIO.new(compressed_data) +reader = Zstd::StreamReader.new(io) + +# Read and output the decompressed data +puts reader.read(10) # 'abc' +puts reader.read(10) # 'def' +puts reader.read(10) # '' (end of data) +``` + + ## JRuby This gem does not support JRuby. diff --git a/lib/zstd-ruby.rb b/lib/zstd-ruby.rb index cdc5d74..4e0d54d 100644 --- a/lib/zstd-ruby.rb +++ b/lib/zstd-ruby.rb @@ -1,5 +1,7 @@ require "zstd-ruby/version" require "zstd-ruby/zstdruby" +require "zstd-ruby/stream_writer" +require "zstd-ruby/stream_reader" module Zstd end diff --git a/spec/zstd-ruby-stream_reader_spec.rb b/spec/zstd-ruby-stream_reader_spec.rb index 648eafb..4d25709 100644 --- a/spec/zstd-ruby-stream_reader_spec.rb +++ b/spec/zstd-ruby-stream_reader_spec.rb @@ -1,7 +1,5 @@ require "spec_helper" require 'zstd-ruby' -require 'zstd-ruby/stream_writer' -require 'zstd-ruby/stream_reader' require 'pry' RSpec.describe Zstd::StreamReader do diff --git a/spec/zstd-ruby-stream_writer_spec.rb b/spec/zstd-ruby-stream_writer_spec.rb index 295c3e6..369aab5 100644 --- a/spec/zstd-ruby-stream_writer_spec.rb +++ b/spec/zstd-ruby-stream_writer_spec.rb @@ -1,6 +1,5 @@ require "spec_helper" require 'zstd-ruby' -require 'zstd-ruby/stream_writer' RSpec.describe Zstd::StreamWriter do describe 'write' do