uringmachine 1.0.5 → 1.0.6

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: 8c4ce5de22052f74a5386dafe18ff4f021db995b6a6b120516a98e0f81783222
4
- data.tar.gz: 64b51a3e8c2e1d5392c6cd8c4c995c09b506de554a537bad14a3074702fb0926
3
+ metadata.gz: 1c37bb6e6971036cefa78d76efbb4425f843087b4b4f5e24fe16e695920746b8
4
+ data.tar.gz: 144e109b5dfa199adda69387c7229c78393f3ee8b0a45f545db76934f896ef2c
5
5
  SHA512:
6
- metadata.gz: 458534cc0ceec394b4dcf32829f62708ac1c68a8e7adf71f4bb48fe00195594805fe22ecc990edc38790b44e9609eeee00ca0c537bc316136e00bb3e87b69577
7
- data.tar.gz: d955545beb0ba009b85ae3fa11619bf3a8869ad97474dd041e57d2c903555418e40e22eae2707a4e936563196162cec197ba55f516fb475cdb6f71da62fb9e87
6
+ metadata.gz: 3d19ae0d9c4056c691a8b9c93901f759e2b149ebd275d8a5d1e0dcfc33e2308eef0e583541b2ce90b69d55efc20b4ab0c7415f4e44d0c9753b07e733bc965e90
7
+ data.tar.gz: 697653d6d9120bcbece655bf530e1e87e9fc461e2052bd20b8666f344440ee11898b569c3d98a7477c39dd11bdf6ff03fc6b1e08f953c257a84fb0aea58a882f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.6 2026-10-01
2
+
3
+ - Add `UM#file_read` convenience method
4
+
1
5
  # 1.0.5 2026-10-01
2
6
 
3
7
  - Add support for regular files in UM::IO with :file mode
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UringMachine
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
data/lib/uringmachine.rb CHANGED
@@ -50,7 +50,7 @@ class UringMachine
50
50
  end
51
51
 
52
52
  # Runs the given block in the given fiber. This method is used to run fibers
53
- # indirectly.
53
+ # indirectly. See FiberScheduler#fiber
54
54
  #
55
55
  # @param fiber [Fiber] fiber
56
56
  # @param block [Proc] block to run
@@ -202,9 +202,10 @@ class UringMachine
202
202
  # the type of target and how it is read from:
203
203
  #
204
204
  # - :fd - read from the given fd using the buffer pool (default mode)
205
+ # - :file - read from a regular file
205
206
  # - :socket - receive from the given socket fd using the buffer pool
206
207
  # - :ssl - read from the given SSL socket
207
- #
208
+ #
208
209
  # If a block is given, the block will be called with the IO instance as
209
210
  # argument and the method will return the block's return value.
210
211
  #
@@ -220,6 +221,17 @@ class UringMachine
220
221
  res
221
222
  end
222
223
 
224
+ # call-seq:
225
+ # machine.file_read(fn) -> data
226
+ #
227
+ # Reads and returns the content of the given filename, with a maximum length of 1GB.
228
+ #
229
+ # @param fn [String] filename
230
+ # @return [String] file content
231
+ def file_read(fn)
232
+ open(fn, O_RDONLY) { io(it, :file).read(-(1 << 30)) }
233
+ end
234
+
223
235
  # Creates, binds and sets up a TCP socket for listening on the given host and
224
236
  # port.
225
237
  #
data/test/test_um.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'helper'
4
4
  require 'socket'
5
+ require 'tempfile'
5
6
 
6
7
  class UringMachineTest < Minitest::Test
7
8
  def test_kernel_version
@@ -3520,6 +3521,23 @@ class IOMethodTest < UMBaseTest
3520
3521
  end
3521
3522
  end
3522
3523
 
3524
+ class FileHelperMethodsTest < UMBaseTest
3525
+ def setup
3526
+ super
3527
+ @fn = Tempfile.new('uringmachine_test_io_from_file').path
3528
+ end
3529
+
3530
+ def test_file_read
3531
+ IO.write(@fn, 'foobar' * 321)
3532
+ buf = machine.file_read(@fn)
3533
+ assert_equal 'foobar' * 321, buf
3534
+ end
3535
+
3536
+ def test_file_read_bad_fn
3537
+ assert_raises(Errno::ENOENT) { machine.file_read(@fn + '-missing') }
3538
+ end
3539
+ end
3540
+
3523
3541
  class TCPHelperMethodsTest < UMBaseTest
3524
3542
  def setup
3525
3543
  super
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uringmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner