philiprehberger-gzip_kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fbd25c13b81efd122da745592b41f230c98c5519bb293bf69e01e177e3334401
4
+ data.tar.gz: b09280836757edb10b5c8f582ebe3012a0c1825161ac55f823dae7c55b3d9270
5
+ SHA512:
6
+ metadata.gz: 167a67368bbd124938ea30e22cf5aab83a7b8a8b65499c3719f38ffa49ab7845357c1d3715c84ebeb19bca3ba9b345afbf1e6d93fed0b7b35879f54e5dc3e8ad
7
+ data.tar.gz: 1bd92f01e5be0ddfdc63639874c4d8ced218de7e9b3f11126e93a758aba6649e3fd22fe4d63a86b23f91097a92c7505bb531423d92b673dd71411316ddee3ba8
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this gem will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-03-26
11
+
12
+ ### Added
13
+ - Initial release
14
+ - `GzipKit.compress` and `GzipKit.decompress` for string compression
15
+ - `GzipKit.compress_file` and `GzipKit.decompress_file` for file operations
16
+ - `GzipKit.compress_stream` and `GzipKit.decompress_stream` for streaming IO
17
+ - Configurable compression level via `level:` keyword argument
18
+ - 64KB chunk-based streaming for memory-efficient processing
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 philiprehberger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # philiprehberger-gzip_kit
2
+
3
+ [![Tests](https://github.com/philiprehberger/rb-gzip-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/philiprehberger/rb-gzip-kit/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/philiprehberger-gzip_kit.svg)](https://rubygems.org/gems/philiprehberger-gzip_kit)
5
+ [![License](https://img.shields.io/github/license/philiprehberger/rb-gzip-kit)](LICENSE)
6
+ [![Sponsor](https://img.shields.io/badge/sponsor-GitHub%20Sponsors-ec6cb9)](https://github.com/sponsors/philiprehberger)
7
+
8
+ Gzip compression and decompression with streaming support
9
+
10
+ ## Requirements
11
+
12
+ - Ruby >= 3.1
13
+
14
+ ## Installation
15
+
16
+ Add to your Gemfile:
17
+
18
+ ```ruby
19
+ gem "philiprehberger-gzip_kit"
20
+ ```
21
+
22
+ Or install directly:
23
+
24
+ ```bash
25
+ gem install philiprehberger-gzip_kit
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require "philiprehberger/gzip_kit"
32
+
33
+ compressed = Philiprehberger::GzipKit.compress("Hello, world!")
34
+ original = Philiprehberger::GzipKit.decompress(compressed)
35
+ ```
36
+
37
+ ### Compression Levels
38
+
39
+ ```ruby
40
+ require "philiprehberger/gzip_kit"
41
+
42
+ # Fast compression
43
+ fast = Philiprehberger::GzipKit.compress(data, level: Zlib::BEST_SPEED)
44
+
45
+ # Maximum compression
46
+ small = Philiprehberger::GzipKit.compress(data, level: Zlib::BEST_COMPRESSION)
47
+
48
+ # No compression (store only)
49
+ raw = Philiprehberger::GzipKit.compress(data, level: Zlib::NO_COMPRESSION)
50
+ ```
51
+
52
+ ### File Operations
53
+
54
+ ```ruby
55
+ require "philiprehberger/gzip_kit"
56
+
57
+ # Compress a file
58
+ Philiprehberger::GzipKit.compress_file("data.txt", "data.txt.gz")
59
+
60
+ # Decompress a file
61
+ Philiprehberger::GzipKit.decompress_file("data.txt.gz", "data.txt")
62
+
63
+ # Compress with custom level
64
+ Philiprehberger::GzipKit.compress_file("data.txt", "data.txt.gz", level: Zlib::BEST_COMPRESSION)
65
+ ```
66
+
67
+ ### Streaming
68
+
69
+ ```ruby
70
+ require "philiprehberger/gzip_kit"
71
+
72
+ # Compress from one IO to another
73
+ File.open("input.txt", "rb") do |input|
74
+ File.open("output.gz", "wb") do |output|
75
+ Philiprehberger::GzipKit.compress_stream(input, output)
76
+ end
77
+ end
78
+
79
+ # Decompress from one IO to another
80
+ File.open("output.gz", "rb") do |input|
81
+ File.open("restored.txt", "wb") do |output|
82
+ Philiprehberger::GzipKit.decompress_stream(input, output)
83
+ end
84
+ end
85
+ ```
86
+
87
+ ## API
88
+
89
+ | Method | Description |
90
+ |--------|-------------|
91
+ | `GzipKit.compress(string, level:)` | Compress a string to gzip bytes |
92
+ | `GzipKit.decompress(data)` | Decompress gzip bytes to a string |
93
+ | `GzipKit.compress_file(src, dest, level:)` | Compress a file to a gzip file |
94
+ | `GzipKit.decompress_file(src, dest)` | Decompress a gzip file to a regular file |
95
+ | `GzipKit.compress_stream(io_in, io_out, level:)` | Streaming compression in 64KB chunks |
96
+ | `GzipKit.decompress_stream(io_in, io_out)` | Streaming decompression in 64KB chunks |
97
+
98
+ ## Development
99
+
100
+ ```bash
101
+ bundle install
102
+ bundle exec rspec
103
+ bundle exec rubocop
104
+ ```
105
+
106
+ ## License
107
+
108
+ [MIT](LICENSE)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Philiprehberger
4
+ module GzipKit
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zlib"
4
+ require "stringio"
5
+ require_relative "gzip_kit/version"
6
+
7
+ module Philiprehberger
8
+ module GzipKit
9
+ class Error < StandardError; end
10
+
11
+ CHUNK_SIZE = 64 * 1024
12
+
13
+ # Compress a string to gzip bytes.
14
+ #
15
+ # @param string [String] the data to compress
16
+ # @param level [Integer] compression level (Zlib::DEFAULT_COMPRESSION by default)
17
+ # @return [String] gzip-compressed bytes
18
+ def self.compress(string, level: Zlib::DEFAULT_COMPRESSION)
19
+ io_out = StringIO.new
20
+ io_out.binmode
21
+ gz = Zlib::GzipWriter.new(io_out, level)
22
+ gz.write(string)
23
+ gz.close
24
+ io_out.string
25
+ end
26
+
27
+ # Decompress gzip bytes to a string.
28
+ #
29
+ # @param data [String] gzip-compressed bytes
30
+ # @return [String] decompressed string
31
+ # @raise [Zlib::GzipFile::Error] if the data is not valid gzip
32
+ def self.decompress(data)
33
+ io_in = StringIO.new(data)
34
+ io_in.binmode
35
+ gz = Zlib::GzipReader.new(io_in)
36
+ gz.read
37
+ ensure
38
+ gz&.close
39
+ end
40
+
41
+ # Compress a file to a gzip file.
42
+ #
43
+ # @param src [String] path to the source file
44
+ # @param dest [String] path to the destination gzip file
45
+ # @param level [Integer] compression level (Zlib::DEFAULT_COMPRESSION by default)
46
+ # @return [void]
47
+ def self.compress_file(src, dest, level: Zlib::DEFAULT_COMPRESSION)
48
+ File.open(src, "rb") do |io_in|
49
+ File.open(dest, "wb") do |io_out|
50
+ compress_stream(io_in, io_out, level: level)
51
+ end
52
+ end
53
+ end
54
+
55
+ # Decompress a gzip file to a regular file.
56
+ #
57
+ # @param src [String] path to the gzip source file
58
+ # @param dest [String] path to the destination file
59
+ # @return [void]
60
+ def self.decompress_file(src, dest)
61
+ File.open(src, "rb") do |io_in|
62
+ File.open(dest, "wb") do |io_out|
63
+ decompress_stream(io_in, io_out)
64
+ end
65
+ end
66
+ end
67
+
68
+ # Streaming compression from one IO to another, reading in 64KB chunks.
69
+ #
70
+ # @param io_in [IO] readable input stream
71
+ # @param io_out [IO] writable output stream
72
+ # @param level [Integer] compression level (Zlib::DEFAULT_COMPRESSION by default)
73
+ # @return [void]
74
+ def self.compress_stream(io_in, io_out, level: Zlib::DEFAULT_COMPRESSION)
75
+ gz = Zlib::GzipWriter.new(io_out, level)
76
+ while (chunk = io_in.read(CHUNK_SIZE))
77
+ gz.write(chunk)
78
+ end
79
+ gz.finish
80
+ end
81
+
82
+ # Streaming decompression from one IO to another, reading in 64KB chunks.
83
+ #
84
+ # @param io_in [IO] readable input stream containing gzip data
85
+ # @param io_out [IO] writable output stream
86
+ # @return [void]
87
+ def self.decompress_stream(io_in, io_out)
88
+ gz = Zlib::GzipReader.new(io_in)
89
+ while (chunk = gz.read(CHUNK_SIZE))
90
+ io_out.write(chunk)
91
+ end
92
+ ensure
93
+ gz&.close
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: philiprehberger-gzip_kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Philip Rehberger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-03-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple API for gzip compression and decompression with support for strings,
14
+ files, and IO streams. Configurable compression level. Built on Ruby stdlib zlib.
15
+ email:
16
+ - me@philiprehberger.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - LICENSE
23
+ - README.md
24
+ - lib/philiprehberger/gzip_kit.rb
25
+ - lib/philiprehberger/gzip_kit/version.rb
26
+ homepage: https://github.com/philiprehberger/rb-gzip-kit
27
+ licenses:
28
+ - MIT
29
+ metadata:
30
+ homepage_uri: https://github.com/philiprehberger/rb-gzip-kit
31
+ source_code_uri: https://github.com/philiprehberger/rb-gzip-kit
32
+ changelog_uri: https://github.com/philiprehberger/rb-gzip-kit/blob/main/CHANGELOG.md
33
+ bug_tracker_uri: https://github.com/philiprehberger/rb-gzip-kit/issues
34
+ rubygems_mfa_required: 'true'
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.1.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.5.22
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Gzip compression and decompression with streaming support
54
+ test_files: []