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 +4 -4
- data/README.md +19 -0
- data/lib/mini_magick/shell.rb +8 -2
- data/lib/mini_magick/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3e8bb8f330d41946c8be0bb756798727c20e7acc5716fe4b96e4a4e663c5bdb
|
|
4
|
+
data.tar.gz: 9e4b699bd809a7694621475923b8a133feb91e17c49688b6bd25b86e87253f0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/mini_magick/shell.rb
CHANGED
|
@@ -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,
|
|
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
|
data/lib/mini_magick/version.rb
CHANGED