foxify 0.9.1 → 0.9.3

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: 5e8da54e157337458828306835a65bfbcb181af66075d09932127ca411a8320a
4
- data.tar.gz: caf2d236c36f6937402b1172ef092d4dbe18105657a4cd7a4aef770a4f2acd6e
3
+ metadata.gz: 7f26749a717084f16f09d980a516f9091fac7e721d91e4cedbbb881fc69c46a1
4
+ data.tar.gz: b61f00854ef46ef26933be9c3c29cf994932945af640b3ab198eef7716683943
5
5
  SHA512:
6
- metadata.gz: 87abb84bb4ed756f8c78cc12077819b1e0f680b3c30aae08e2d213675ea3a79228c96ef3d1766d91a209319f3161b833da66778b78965ec86e37ef703d44c682
7
- data.tar.gz: '09b84594260f403bd94234c0d1422eba51dd6fd6cc427f5239a44bc9ccd40c48046cf8a3eb99b5da8d9e08b0e440e61e29f7d5f9557353966af79f427c1a1211'
6
+ metadata.gz: '0256939b9a297eb2df40c13fc2467d64c6256462d2dbcb884addac3e0016072d774ecf1b1d53eda9770ec361c54caf64aa47b724fe03722cade6fe63f237aaba'
7
+ data.tar.gz: a07b91c76af00c10be2438d1a215d6b45adc39b024813805c3c5535cdb0805fb52ff8e59cd4cf6d38409b80c3e9c31aad9c4d38abc979a0b43af0f70844774e0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## [0.9.3] - 2025-03-31
6
+
7
+ - Switch to pointers for data passing
8
+ - [#2](https://github.com/orlon-pro/foxify/issues/2#issue-2782741001) Implement the `file` class method
9
+ - Update dependencies
10
+
11
+ ## [0.9.2] - 2025-01-12
12
+
13
+ - Implement `hexdigest` class method
14
+ - Add `<<` alias for `update`
15
+ - Add benchmark spec
16
+ - Improve gemspec (dependencies)
17
+
1
18
  ## [0.9.1] - 2025-01-12
2
19
 
3
20
  - Fix gemspec allowed_push_host
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)
@@ -26,6 +28,8 @@ module Foxify
26
28
  self
27
29
  end
28
30
 
31
+ alias :<< update
32
+
29
33
  def hexdigest
30
34
  raise Foxify::Error, "Invalid state - this is already finalized" if @finalized
31
35
 
@@ -34,6 +38,18 @@ module Foxify
34
38
  end
35
39
  end
36
40
 
41
+ def self.hexdigest(data)
42
+ new.update(data).hexdigest
43
+ end
44
+
45
+ def self.file(path)
46
+ new.tap do |t|
47
+ stream = File.open(path, "rb")
48
+ t.update stream.read(CHUNK_SIZE) until stream.eof?
49
+ stream.close
50
+ end
51
+ end
52
+
37
53
  def ==(other)
38
54
  self.class == other.class && state == other.state && finalized == other.finalized
39
55
  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)
@@ -26,6 +28,8 @@ module Foxify
26
28
  self
27
29
  end
28
30
 
31
+ alias :<< update
32
+
29
33
  def hexdigest
30
34
  raise Foxify::Error, "Invalid state - this is already finalized" if @finalized
31
35
 
@@ -34,6 +38,18 @@ module Foxify
34
38
  end
35
39
  end
36
40
 
41
+ def self.hexdigest(data)
42
+ new.update(data).hexdigest
43
+ end
44
+
45
+ def self.file(path)
46
+ new.tap do |t|
47
+ stream = File.open(path, "rb")
48
+ t.update stream.read(CHUNK_SIZE) until stream.eof?
49
+ stream.close
50
+ end
51
+ end
52
+
37
53
  def ==(other)
38
54
  self.class == other.class && state == other.state && finalized == other.finalized
39
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Foxify
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.3"
5
5
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foxify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.3
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-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: go_gem
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
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'
26
+ version: 0.7.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: msgpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.7'
41
41
  description: Provides ruby implementation of resumable digests based on golang implementation
42
42
  email:
43
43
  - zarkov@tor.ch
@@ -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