mini_magick 5.3.3 → 5.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce89fb8c4944594e97e5fa8bb017b17ad827f6dd06df2effd4155b83bf8a4215
4
- data.tar.gz: 4a130f7c8963143f29bad7432be8d90a68892716dffd479e56edffc45655e0a4
3
+ metadata.gz: b3e8bb8f330d41946c8be0bb756798727c20e7acc5716fe4b96e4a4e663c5bdb
4
+ data.tar.gz: 9e4b699bd809a7694621475923b8a133feb91e17c49688b6bd25b86e87253f0b
5
5
  SHA512:
6
- metadata.gz: ed544ea77778b627fd58ff4a80665d9560ee67d2fe4d88fc391450bf53f01647f6d515c730d97ffa301619a46334134616dbb5fc1e4f0e40ff09e81355154fbe
7
- data.tar.gz: 6aaf746cdb19db2f15bbbf3d55fdb839c0df1c9504f1ba8afc8a7b822329fe61c5eac7d6f07337f2735df0c00da089cf46f3e2f387789a46b1c0e41661041469
6
+ metadata.gz: 49dc51bf6819aa5ac6a981305f0f31b6b67859f67b54b78c58602e7c82fff36bdbec5d97d8d623f40a2ec5665df438fdb966d8143a91c645019e2705a41e0006
7
+ data.tar.gz: 9dfca63b5a1e65d71bdc1604aa1fb316063fef145b62fe1832c7c86de7dbba7fe2ab3e7df74e9aa143c421e1b74063a35ce3ac9f1eb12f9f52bbe719a625f2d7
data/README.md CHANGED
@@ -437,6 +437,25 @@ content = MiniMagick.convert do |convert|
437
437
  end
438
438
  ```
439
439
 
440
+ ### Inheriting file descriptors
441
+
442
+ If the input is a file this process already has open, you can have the command
443
+ inherit the descriptor with the `:inherit_fds` option and name it as
444
+ `/dev/fd/N`, rather than writing out a copy for the command to read:
445
+
446
+ ```rb
447
+ File.open("input.jpg", "rb") do |file|
448
+ MiniMagick.identify(inherit_fds: [file]) do |identify|
449
+ identify << "/dev/fd/#{file.fileno}"
450
+ end
451
+ end
452
+ ```
453
+
454
+ Each IO given to `:inherit_fds` is inherited at the same file descriptor
455
+ number. Without it the descriptor is close-on-exec, so `/dev/fd/N` does not
456
+ exist in the command. The command's own standard streams occupy 0, 1 and 2, so
457
+ those cannot be inherited.
458
+
440
459
  ### Capturing STDERR
441
460
 
442
461
  Some MiniMagick tools such as `compare` output the result of the command on
@@ -25,18 +25,24 @@ module MiniMagick
25
25
  [stdout, stderr, status]
26
26
  end
27
27
 
28
- def execute(command, stdin: "", timeout: MiniMagick.timeout)
28
+ def execute(command, stdin: "", timeout: MiniMagick.timeout, inherit_fds: [])
29
29
  env = MiniMagick.restricted_env ? ENV.to_h.slice("HOME", "PATH", "LANG") : {} # Using #to_h for Ruby 2.5 compatibility.
30
30
  env.merge!(MiniMagick.cli_env)
31
31
  env["MAGICK_TIME_LIMIT"] = timeout.to_s if timeout
32
32
 
33
33
  stdout, stderr, status = log(command.join(" ")) do
34
+ options = { unsetenv_others: MiniMagick.restricted_env }
35
+ # Descriptors are close-on-exec, and spawn clears that only for the ones
36
+ # its redirect map names, so /dev/fd/N does not exist in the command
37
+ # unless the descriptor is named here.
38
+ inherit_fds.each { |io| options[io.fileno] = io.fileno }
39
+
34
40
  # We would ideally use Open3.capture3, but it doesn't allow us to
35
41
  # terminate the command after timing out. We can't rely solely on
36
42
  # ImageMagick's own $MAGICK_TIME_LIMIT for this, because it's only
37
43
  # checked periodically inside ImageMagick's processing loops, so it
38
44
  # can fire too late (or not at all) depending on the operation.
39
- Open3.popen3(env, *command, unsetenv_others: MiniMagick.restricted_env) do |stdin_io, stdout_io, stderr_io, wait_thread|
45
+ Open3.popen3(env, *command, options) do |stdin_io, stdout_io, stderr_io, wait_thread|
40
46
  stdin_io.binmode
41
47
  stdout_io.binmode
42
48
  stderr_io.binmode
@@ -8,8 +8,8 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 5
11
- MINOR = 3
12
- TINY = 3
11
+ MINOR = 4
12
+ TINY = 0
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.3
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson