peasy-compress 0.1.1
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 +7 -0
- data/lib/peasy_compress/engine.rb +44 -0
- data/lib/peasy_compress/version.rb +5 -0
- data/lib/peasy_compress.rb +4 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3932ef9c8edcea98f121825496da2ea7c4015497fb690698eede9eff9c6d5f54
|
|
4
|
+
data.tar.gz: cc82b461268bbf60506fed28f8f1366597a81e00fc9426f1eb1bc5d35fbd9e61
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 59a0024e14e62dc9dd25dd137e689b124772c8909554576a9590de42464be0a69a769b405016626b1d500f629bde9164b6d555dda51cad94d41f4b9cefeb955f
|
|
7
|
+
data.tar.gz: 4be8168bf59e5d8e3d85a5ab46adcec7be119c981a85557118815c3224922ef66e24b0e31cba1fe38742b7fdd58e7a5bec31f0d295ac9ade72962255d03c6cc8
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "zlib"
|
|
4
|
+
require "stringio"
|
|
5
|
+
require "base64"
|
|
6
|
+
|
|
7
|
+
module PeasyCompress
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def gzip(data)
|
|
11
|
+
io = StringIO.new
|
|
12
|
+
io.set_encoding("BINARY")
|
|
13
|
+
gz = Zlib::GzipWriter.new(io)
|
|
14
|
+
gz.write(data)
|
|
15
|
+
gz.close
|
|
16
|
+
io.string
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def gunzip(data)
|
|
20
|
+
io = StringIO.new(data)
|
|
21
|
+
Zlib::GzipReader.new(io).read
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def deflate(data, level: Zlib::DEFAULT_COMPRESSION)
|
|
25
|
+
Zlib::Deflate.deflate(data, level)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def inflate(data)
|
|
29
|
+
Zlib::Inflate.inflate(data)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def compress_ratio(original_size, compressed_size)
|
|
33
|
+
return 0.0 if original_size.zero?
|
|
34
|
+
((1.0 - compressed_size.to_f / original_size) * 100).round(1)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def gzip_base64(data)
|
|
38
|
+
Base64.strict_encode64(gzip(data))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def gunzip_base64(data)
|
|
42
|
+
gunzip(Base64.strict_decode64(data))
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: peasy-compress
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- PeasyTools
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Compression library for Ruby — gzip, deflate, and zlib compression with
|
|
13
|
+
ratio calculation. Uses Ruby stdlib Zlib, zero external dependencies.
|
|
14
|
+
email:
|
|
15
|
+
- hello@peasytools.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/peasy_compress.rb
|
|
21
|
+
- lib/peasy_compress/engine.rb
|
|
22
|
+
- lib/peasy_compress/version.rb
|
|
23
|
+
homepage: https://peasytools.com
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata:
|
|
27
|
+
homepage_uri: https://peasytools.com
|
|
28
|
+
source_code_uri: https://github.com/peasytools/peasy-compress-rb
|
|
29
|
+
changelog_uri: https://github.com/peasytools/peasy-compress-rb/blob/main/CHANGELOG.md
|
|
30
|
+
documentation_uri: https://peasytools.com
|
|
31
|
+
bug_tracker_uri: https://github.com/peasytools/peasy-compress-rb/issues
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
requirements: []
|
|
46
|
+
rubygems_version: 4.0.3
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Compression — gzip, deflate, brotli
|
|
49
|
+
test_files: []
|