foxify 0.9.2 → 0.9.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6c198c134f683f8214437bcb5d288035941e50a98c6a6d74da077cd8194bd4e
4
- data.tar.gz: 23910aad730c41f82fd41f6597bdd1ddbba64e83c9457765192a1c5dbe5befad
3
+ metadata.gz: 7671cd8fde08d27bf5e00c9370a44f06da2b71d5d5874c3fdca4d65011c0e058
4
+ data.tar.gz: 4e4a79e2259cbddd9e92f5edd66f771df9536decf9349ffb037af1b6cdeee184
5
5
  SHA512:
6
- metadata.gz: e59aab6810999d6389faf5c4aff6cb5b17bda3dfd116d2f3f7bd5939b8033288076e28c0c7cd1d023f4045aebd0e798b00b85aed15dec2af11b421e54aaa3830
7
- data.tar.gz: f4d94963a90625beac376339584afa2af0549c0f4b5b9bed2ee4781caf63d55e14c5f07c50ecacac3c8fc770617ac8e5a22e588c4060f14f2a94f7c542e5d14e
6
+ metadata.gz: '08f92987ea4a30c7fc1350a35e9ab8664a3912072d23129a268465a8572463ce8db8da1144505af11fc4966d3f04df645b006ab9f030d6479c0416557795c7ec'
7
+ data.tar.gz: 07ee45e51ad19274c87ede7b1535c849f457e7b5847a1c794cd9f0c1b88a5bd626bb3171b373f826898139c616d4e44c2e864f1e07de7791ec52fd7dd32aa09c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## [0.9.4] - 2025-05-24
6
+
7
+ - Add `write` method to support IO-like usage (i.e. `IO.copy_stream`)
8
+ - Update dependencies
9
+
10
+ ## [0.9.3] - 2025-03-31
11
+
12
+ - Switch to pointers for data passing
13
+ - [#2](https://github.com/orlon-pro/foxify/issues/2#issue-2782741001) Implement the `file` class method
14
+ - Update dependencies
15
+
3
16
  ## [0.9.2] - 2025-01-12
4
17
 
5
18
  - Implement `hexdigest` class method
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Test](https://github.com/orlon-pro/foxify/actions/workflows/main.yml/badge.svg)](https://github.com/orlon-pro/foxify/actions/workflows/main.yml)
2
+ [![Gem Version](https://badge.fury.io/rb/foxify.svg)](https://badge.fury.io/rb/foxify)
2
3
 
3
4
  # Foxify
4
5
 
@@ -87,6 +88,12 @@ restored.update("jumps over the lazy dog")
87
88
  restored.hexdigest # returns "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"
88
89
  ```
89
90
 
91
+ ## Mascot
92
+
93
+ You asked for it, here we go:
94
+
95
+ <img src="https://github.com/user-attachments/assets/d24520da-ffa5-4203-b0b6-c0770f1b9964" width="200">
96
+
90
97
  ## Contributing
91
98
 
92
99
  Bug reports and pull requests are welcome on GitHub at https://github.com/orlon-pro/foxify.
data/ext/foxify/foxify.go CHANGED
@@ -19,6 +19,7 @@ import (
19
19
  "encoding/base64"
20
20
  "encoding/hex"
21
21
  "log"
22
+ "unsafe"
22
23
 
23
24
  "github.com/ruby-go-gem/go-gem-wrapper/ruby"
24
25
  )
@@ -58,9 +59,11 @@ func rb_foxify_resumable_sha256_update(_ C.VALUE, state C.VALUE, data C.VALUE) C
58
59
  unmarshaler := h.(encoding.BinaryUnmarshaler)
59
60
  unmarshaler.UnmarshalBinary(s)
60
61
 
61
- buffer := ruby.Value2String(ruby.VALUE(data))
62
- if len(buffer) > 0 {
63
- h.Write([]byte(buffer))
62
+ rValue := ruby.VALUE(data)
63
+ rLength := ruby.RSTRING_LENINT(rValue)
64
+ if rLength > 0 {
65
+ char := ruby.RSTRING_PTR(rValue)
66
+ h.Write(C.GoBytes(unsafe.Pointer(char), C.int(rLength)))
64
67
  }
65
68
 
66
69
  marshaler := h.(encoding.BinaryMarshaler)
@@ -80,9 +83,11 @@ func rb_foxify_resumable_sha1_update(_ C.VALUE, state C.VALUE, data C.VALUE) C.V
80
83
  unmarshaler := h.(encoding.BinaryUnmarshaler)
81
84
  unmarshaler.UnmarshalBinary(s)
82
85
 
83
- buffer := ruby.Value2String(ruby.VALUE(data))
84
- if len(buffer) > 0 {
85
- h.Write([]byte(buffer))
86
+ rValue := ruby.VALUE(data)
87
+ rLength := ruby.RSTRING_LENINT(rValue)
88
+ if rLength > 0 {
89
+ char := ruby.RSTRING_PTR(rValue)
90
+ h.Write(C.GoBytes(unsafe.Pointer(char), C.int(rLength)))
86
91
  }
87
92
 
88
93
  marshaler := h.(encoding.BinaryMarshaler)
@@ -5,6 +5,8 @@ require "msgpack"
5
5
  module Foxify
6
6
  # A resumable SHA1 implementation
7
7
  class ResumableSHA1
8
+ CHUNK_SIZE = 1024 * 1024 * 5
9
+
8
10
  attr_reader :state, :finalized
9
11
 
10
12
  def initialize(state = nil, finalized: false)
@@ -28,6 +30,11 @@ module Foxify
28
30
 
29
31
  alias :<< update
30
32
 
33
+ def write(data)
34
+ update(data)
35
+ data.size
36
+ end
37
+
31
38
  def hexdigest
32
39
  raise Foxify::Error, "Invalid state - this is already finalized" if @finalized
33
40
 
@@ -40,6 +47,14 @@ module Foxify
40
47
  new.update(data).hexdigest
41
48
  end
42
49
 
50
+ def self.file(path)
51
+ new.tap do |t|
52
+ stream = File.open(path, "rb")
53
+ t.update stream.read(CHUNK_SIZE) until stream.eof?
54
+ stream.close
55
+ end
56
+ end
57
+
43
58
  def ==(other)
44
59
  self.class == other.class && state == other.state && finalized == other.finalized
45
60
  end
@@ -5,6 +5,8 @@ require "msgpack"
5
5
  module Foxify
6
6
  # A resumable SHA256 implementation
7
7
  class ResumableSHA256
8
+ CHUNK_SIZE = 1024 * 1024 * 5
9
+
8
10
  attr_reader :state, :finalized
9
11
 
10
12
  def initialize(state = nil, finalized: false)
@@ -28,6 +30,11 @@ module Foxify
28
30
 
29
31
  alias :<< update
30
32
 
33
+ def write(data)
34
+ update(data)
35
+ data.size
36
+ end
37
+
31
38
  def hexdigest
32
39
  raise Foxify::Error, "Invalid state - this is already finalized" if @finalized
33
40
 
@@ -40,6 +47,14 @@ module Foxify
40
47
  new.update(data).hexdigest
41
48
  end
42
49
 
50
+ def self.file(path)
51
+ new.tap do |t|
52
+ stream = File.open(path, "rb")
53
+ t.update stream.read(CHUNK_SIZE) until stream.eof?
54
+ stream.close
55
+ end
56
+ end
57
+
43
58
  def ==(other)
44
59
  self.class == other.class && state == other.state && finalized == other.finalized
45
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Foxify
4
- VERSION = "0.9.2"
4
+ VERSION = "0.9.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foxify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr. Zarkov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-12 00:00:00.000000000 Z
11
+ date: 2025-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: go_gem
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.6'
19
+ version: 0.7.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.6'
26
+ version: 0.7.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: msgpack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.5.10
89
+ rubygems_version: 3.5.22
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Implementation of resumable digests and other nifty foxalike things