qpdf-binary 12.4.2.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 +7 -0
- data/CHANGELOG.md +25 -0
- data/MIT-LICENSE +20 -0
- data/README.md +201 -0
- data/THIRD_PARTY_NOTICES.md +46 -0
- data/exe/qpdf +18 -0
- data/lib/qpdf-binary.rb +5 -0
- data/lib/qpdf_binary/errors.rb +17 -0
- data/lib/qpdf_binary/extractor.rb +81 -0
- data/lib/qpdf_binary/platform.rb +51 -0
- data/lib/qpdf_binary/version.rb +16 -0
- data/lib/qpdf_binary.rb +89 -0
- data/libexec/qpdf-linux-aarch64.buildinfo +66 -0
- data/libexec/qpdf-linux-aarch64.gz +0 -0
- data/libexec/qpdf-linux-x86_64.buildinfo +66 -0
- data/libexec/qpdf-linux-x86_64.gz +0 -0
- data/licenses/libjpeg-turbo-LICENSE.md +135 -0
- data/licenses/libjpeg-turbo-README.ijg +260 -0
- data/licenses/qpdf-LICENSE.txt +202 -0
- data/licenses/qpdf-NOTICE.md +42 -0
- data/licenses/zlib-LICENSE.txt +26 -0
- metadata +187 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2c9c2050ebbc81c1d9ac9c99bc48ff291cad984a3dc8cb345ee7f425e7c1f8f5
|
|
4
|
+
data.tar.gz: e495f9ddca0fb591bdad00ee74d787f2a95efe5ac338a4618b6607a0f9a48564
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ac6582b028a98250721a86ee597e2b874bad2a106579b84ea7b565635cdd590fd13bc2a14ebf8dd2fafc75428e1cee42e869fcced487e58926ecc92fb3a67099
|
|
7
|
+
data.tar.gz: 032100d246da0b77ce24b0299e9aaa66f89a80fdbc00298fd6cf4b983f98eeb8fe03c3244b975c9434a3aee9d6a9bf0c1aa6e7f0ae82b9264c4eacc87d9b5a5e
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
Versions are the packaged qpdf version plus a packaging revision; see the
|
|
7
|
+
README's Versioning section.
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
## [12.4.2.0] - 2026-11-20
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- Fully static qpdf 12.4.2 executables for Linux x86_64 and aarch64, built
|
|
15
|
+
against musl with zlib, libjpeg-turbo and OpenSSL linked in. The build
|
|
16
|
+
verifies the source tarball's SHA-256 and rejects any binary that needs a
|
|
17
|
+
dynamic loader or shared libraries.
|
|
18
|
+
- A `qpdf` executable that passes all arguments to the bundled binary.
|
|
19
|
+
- `QpdfBinary.path`, which decompresses the binary for the running platform
|
|
20
|
+
on first use and returns its path. It falls back from the gem directory to
|
|
21
|
+
a per-user cache when the gem directory is read-only, and honours
|
|
22
|
+
`QPDF_BINARY_CACHE_DIR`.
|
|
23
|
+
- `QpdfBinary::UnsupportedPlatformError`, `MissingBinaryError` and
|
|
24
|
+
`ExtractionError`, all subclasses of `QpdfBinary::Error`.
|
|
25
|
+
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright Durable Programming Team
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# qpdf-binary
|
|
2
|
+
|
|
3
|
+
[](https://github.com/durable-oss/qpdf_binary_gem/actions/workflows/ci.yml)
|
|
4
|
+
[](https://rubygems.org/gems/qpdf-binary)
|
|
5
|
+
|
|
6
|
+
[qpdf](https://qpdf.readthedocs.io/) as a Ruby gem. qpdf is a command-line
|
|
7
|
+
tool that splits, merges, encrypts, decrypts, linearizes and repairs PDFs
|
|
8
|
+
without changing their content.
|
|
9
|
+
|
|
10
|
+
The gem ships qpdf 12.4.2 as **fully static Linux executables** for x86_64 and
|
|
11
|
+
aarch64. They are built against musl, with zlib, libjpeg-turbo, OpenSSL and
|
|
12
|
+
libstdc++ linked in, so they depend on no shared libraries at all. The same
|
|
13
|
+
binary runs on Debian, Ubuntu, RHEL, Alpine, and distroless or `scratch`
|
|
14
|
+
container images. You don't need to `apt-get install qpdf` in your Dockerfile.
|
|
15
|
+
|
|
16
|
+
Packaging follows the
|
|
17
|
+
[wkhtmltopdf-binary](https://github.com/zakird/wkhtmltopdf_binary_gem) gem:
|
|
18
|
+
the gzipped binaries live inside the gem, and the one for your platform is
|
|
19
|
+
decompressed the first time it runs.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
gem "qpdf-binary"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
bundle install
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### From the command line
|
|
34
|
+
|
|
35
|
+
Installing the gem puts `qpdf` on your `PATH`:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
qpdf --version
|
|
39
|
+
qpdf --linearize input.pdf output.pdf
|
|
40
|
+
qpdf --empty --pages a.pdf b.pdf -- merged.pdf
|
|
41
|
+
qpdf --encrypt --user-password=secret --owner-password=owner --bits=256 -- in.pdf out.pdf
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Every argument goes to qpdf unchanged. The
|
|
45
|
+
[qpdf manual](https://qpdf.readthedocs.io/en/stable/cli.html) covers the rest.
|
|
46
|
+
|
|
47
|
+
Under `bundle exec`, or wherever the RubyGems executable directory comes
|
|
48
|
+
before `/usr/bin` on your `PATH`, this `qpdf` shadows a system-installed one.
|
|
49
|
+
Call `/usr/bin/qpdf` explicitly when you want the system copy.
|
|
50
|
+
|
|
51
|
+
### From Ruby
|
|
52
|
+
|
|
53
|
+
`QpdfBinary.path` returns the path to the executable, extracting it on first
|
|
54
|
+
use:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
require "qpdf_binary"
|
|
58
|
+
require "open3"
|
|
59
|
+
|
|
60
|
+
system(QpdfBinary.path, "--linearize", "in.pdf", "out.pdf", exception: true)
|
|
61
|
+
|
|
62
|
+
pages, status = Open3.capture2(QpdfBinary.path, "--show-npages", "report.pdf")
|
|
63
|
+
pages.to_i if status.success?
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Pass arguments as separate strings, as above. qpdf is then run without a
|
|
67
|
+
shell, so file names with spaces or shell metacharacters are safe.
|
|
68
|
+
|
|
69
|
+
Other libraries that shell out to qpdf can usually be pointed at
|
|
70
|
+
`QpdfBinary.path`.
|
|
71
|
+
|
|
72
|
+
### Errors
|
|
73
|
+
|
|
74
|
+
Everything raised is a subclass of `QpdfBinary::Error`:
|
|
75
|
+
|
|
76
|
+
| Error | When |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `QpdfBinary::UnsupportedPlatformError` | The host is not Linux x86_64 or aarch64 |
|
|
79
|
+
| `QpdfBinary::MissingBinaryError` | The gem was built without this platform's binary (see [Building from source](#building-from-source)) |
|
|
80
|
+
| `QpdfBinary::ExtractionError` | No candidate directory was writable |
|
|
81
|
+
|
|
82
|
+
## Where the binary is extracted
|
|
83
|
+
|
|
84
|
+
On first use, the binary is decompressed into the first of these directories
|
|
85
|
+
that works:
|
|
86
|
+
|
|
87
|
+
1. `$QPDF_BINARY_CACHE_DIR/<gem version>/`, if `QPDF_BINARY_CACHE_DIR` is set
|
|
88
|
+
2. The gem's own `libexec/` directory
|
|
89
|
+
3. `${XDG_CACHE_HOME:-~/.cache}/qpdf-binary/<gem version>/`
|
|
90
|
+
|
|
91
|
+
After that, the extracted copy is reused. It is written to a temporary file
|
|
92
|
+
and renamed into place, so concurrent first runs, such as several Puma workers
|
|
93
|
+
booting at once, never see a partial file.
|
|
94
|
+
|
|
95
|
+
Gems installed by root, or baked into a read-only image, fall through to the
|
|
96
|
+
user cache. If neither directory is writable at runtime, set
|
|
97
|
+
`QPDF_BINARY_CACHE_DIR` to a writable location, or run `qpdf --version` once
|
|
98
|
+
at image build time so the binary is already extracted into `libexec/`:
|
|
99
|
+
|
|
100
|
+
```dockerfile
|
|
101
|
+
RUN bundle install && bundle exec qpdf --version
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The gem never extracts into a shared temporary directory such as `/tmp`, where
|
|
105
|
+
another local user could plant an executable first.
|
|
106
|
+
|
|
107
|
+
## Supported platforms
|
|
108
|
+
|
|
109
|
+
| Platform | Binary |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| Linux x86_64 (glibc or musl) | `libexec/qpdf-linux-x86_64.gz` |
|
|
112
|
+
| Linux aarch64 (glibc or musl) | `libexec/qpdf-linux-aarch64.gz` |
|
|
113
|
+
|
|
114
|
+
macOS and Windows have no fully static equivalent, so they aren't packaged.
|
|
115
|
+
Install qpdf with Homebrew (`brew install qpdf`) or from the
|
|
116
|
+
[qpdf releases](https://github.com/qpdf/qpdf/releases).
|
|
117
|
+
|
|
118
|
+
## Versioning
|
|
119
|
+
|
|
120
|
+
The gem version is the qpdf version plus a packaging revision. `12.4.2.0` is
|
|
121
|
+
the first release of qpdf 12.4.2, and `12.4.2.1` repackages that same qpdf
|
|
122
|
+
(a build fix, a wrapper change). To stay on one qpdf release, pin all three
|
|
123
|
+
leading numbers:
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
gem "qpdf-binary", "~> 12.4.2.0"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The constants are available at runtime:
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
QpdfBinary::QPDF_VERSION # => "12.4.2"
|
|
133
|
+
QpdfBinary::VERSION # => "12.4.2.0"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## How the binaries are built
|
|
137
|
+
|
|
138
|
+
[`builder/Dockerfile`](builder/Dockerfile) compiles qpdf from the release
|
|
139
|
+
tarball on Alpine Linux. The tarball's SHA-256 is pinned in
|
|
140
|
+
[`lib/qpdf_binary/version.rb`](lib/qpdf_binary/version.rb), and the build
|
|
141
|
+
aborts if it doesn't match. The resulting executable has to pass these checks
|
|
142
|
+
before it is exported:
|
|
143
|
+
|
|
144
|
+
- It has no `PT_INTERP` program header and no `DT_NEEDED` entries, so it
|
|
145
|
+
needs no dynamic loader and no shared libraries.
|
|
146
|
+
- `qpdf --version` reports the pinned version.
|
|
147
|
+
- `qpdf --show-crypto` reports exactly `openssl`. qpdf's built-in crypto is
|
|
148
|
+
meant for testing and isn't hardened, so it is compiled out.
|
|
149
|
+
- It encrypts a PDF with AES-256, decrypts it, and checks the result.
|
|
150
|
+
- It decodes a JPEG stream through libjpeg-turbo.
|
|
151
|
+
|
|
152
|
+
CI builds each architecture on a native GitHub runner, then runs the binary in
|
|
153
|
+
`gcr.io/distroless/static-debian12`, an image that contains no libc. The
|
|
154
|
+
release workflow publishes those same artifacts, and attaches the raw `.gz`
|
|
155
|
+
files to the GitHub Release.
|
|
156
|
+
|
|
157
|
+
Each binary ships with a `.buildinfo` file listing the exact Alpine package
|
|
158
|
+
versions (OpenSSL, zlib, libjpeg-turbo, musl) linked into it.
|
|
159
|
+
|
|
160
|
+
### Building from source
|
|
161
|
+
|
|
162
|
+
The binaries are build products and are not in git. A gem built from a fresh
|
|
163
|
+
checkout has to produce them first. This needs Docker:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
bin/build-binaries # x86_64 and aarch64
|
|
167
|
+
bin/build-binaries x86_64 # just one
|
|
168
|
+
rake binaries ARCH=x86_64 # the same, through rake
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Building for an architecture other than the host's goes through QEMU
|
|
172
|
+
emulation. Register it first with
|
|
173
|
+
`docker run --privileged --rm tonistiigi/binfmt --install arm64`, and expect
|
|
174
|
+
the build to be slow.
|
|
175
|
+
|
|
176
|
+
`rake build` refuses to package the gem unless every supported platform has a
|
|
177
|
+
binary in `libexec/`.
|
|
178
|
+
|
|
179
|
+
## Licensing
|
|
180
|
+
|
|
181
|
+
The Ruby code in this gem is MIT licensed; see [MIT-LICENSE](MIT-LICENSE).
|
|
182
|
+
|
|
183
|
+
The bundled qpdf binary is a separate work under the Apache License 2.0, and
|
|
184
|
+
it statically links other open source libraries. See
|
|
185
|
+
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) and the texts in
|
|
186
|
+
[`licenses/`](licenses/), all of which are packaged with the gem.
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
bundle install
|
|
192
|
+
bin/test # unit tests; real-binary tests skip without libexec/
|
|
193
|
+
bundle exec rubocop
|
|
194
|
+
bin/build-binaries x86_64 && bin/test # include the real-binary tests
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the release process.
|
|
198
|
+
|
|
199
|
+
## Contact
|
|
200
|
+
|
|
201
|
+
Durable Programming, LLC: commercial@durableprogramming.com
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
The Ruby code in this gem is MIT licensed (see `MIT-LICENSE`). The qpdf
|
|
4
|
+
executables in `libexec/` are separate works, distributed under their own
|
|
5
|
+
licenses. Each is one static executable that links the components below.
|
|
6
|
+
`libexec/qpdf-linux-<arch>.buildinfo` records the exact package versions used
|
|
7
|
+
for each build.
|
|
8
|
+
|
|
9
|
+
| Component | License | Text |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| [qpdf](https://github.com/qpdf/qpdf) | Apache-2.0 | `licenses/qpdf-LICENSE.txt`, `licenses/qpdf-NOTICE.md` |
|
|
12
|
+
| [OpenSSL](https://www.openssl.org/) 3.x | Apache-2.0 | Same Apache License 2.0 text as `licenses/qpdf-LICENSE.txt` |
|
|
13
|
+
| [libjpeg-turbo](https://libjpeg-turbo.org/) | IJG, BSD-3-Clause, zlib | `licenses/libjpeg-turbo-LICENSE.md`, `licenses/libjpeg-turbo-README.ijg` |
|
|
14
|
+
| [zlib](https://zlib.net/) | zlib | `licenses/zlib-LICENSE.txt` |
|
|
15
|
+
| [musl libc](https://musl.libc.org/) | MIT | Reproduced below |
|
|
16
|
+
| libstdc++ and libgcc (GCC) | GPL-3.0 with the GCC Runtime Library Exception | The exception permits distributing the compiled result under any terms |
|
|
17
|
+
|
|
18
|
+
`bin/build-binaries` copies the qpdf, libjpeg-turbo and zlib texts out of the
|
|
19
|
+
build itself, and CI fails if they drift from the committed copies.
|
|
20
|
+
|
|
21
|
+
This software is based in part on the work of the Independent JPEG Group.
|
|
22
|
+
|
|
23
|
+
## musl libc
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
Copyright © 2005-2020 Rich Felker, et al.
|
|
27
|
+
|
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
29
|
+
a copy of this software and associated documentation files (the
|
|
30
|
+
"Software"), to deal in the Software without restriction, including
|
|
31
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
32
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
33
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
34
|
+
the following conditions:
|
|
35
|
+
|
|
36
|
+
The above copyright notice and this permission notice shall be
|
|
37
|
+
included in all copies or substantial portions of the Software.
|
|
38
|
+
|
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
40
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
41
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
42
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
43
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
44
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
45
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
46
|
+
```
|
data/exe/qpdf
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Runs the static qpdf binary bundled with the qpdf-binary gem, passing every
|
|
5
|
+
# argument through unchanged.
|
|
6
|
+
|
|
7
|
+
require_relative "../lib/qpdf_binary"
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
binary = QpdfBinary.path
|
|
11
|
+
rescue QpdfBinary::Error => e
|
|
12
|
+
warn "qpdf-binary: #{e.message}"
|
|
13
|
+
exit 1
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# The [path, argv0] form never goes through a shell, even when ARGV is empty,
|
|
17
|
+
# and lets qpdf report itself as "qpdf" in its messages.
|
|
18
|
+
exec([binary, "qpdf"], *ARGV)
|
data/lib/qpdf-binary.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module QpdfBinary
|
|
4
|
+
# Base class for every error this gem raises.
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
# Raised when the running OS or CPU has no static qpdf build.
|
|
8
|
+
class UnsupportedPlatformError < Error; end
|
|
9
|
+
|
|
10
|
+
# Raised when the installed gem lacks the binary for a supported platform,
|
|
11
|
+
# which happens when it was built from a git checkout without running
|
|
12
|
+
# `rake binaries` first.
|
|
13
|
+
class MissingBinaryError < Error; end
|
|
14
|
+
|
|
15
|
+
# Raised when the binary cannot be decompressed into any candidate directory.
|
|
16
|
+
class ExtractionError < Error; end
|
|
17
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "securerandom"
|
|
5
|
+
require "zlib"
|
|
6
|
+
|
|
7
|
+
module QpdfBinary
|
|
8
|
+
# Decompresses a gzipped executable into the first writable directory.
|
|
9
|
+
#
|
|
10
|
+
# This is the technique the wkhtmltopdf-binary gem uses: ship compressed
|
|
11
|
+
# binaries, and inflate the one for the running platform on first use. Two
|
|
12
|
+
# changes make it safer to run in production:
|
|
13
|
+
#
|
|
14
|
+
# * The binary is written to a temporary file and renamed into place, so a
|
|
15
|
+
# second process starting at the same moment never executes a half-written
|
|
16
|
+
# file.
|
|
17
|
+
# * When the gem directory is read-only (gems installed by root, read-only
|
|
18
|
+
# container images), extraction moves on to the next candidate directory
|
|
19
|
+
# instead of failing.
|
|
20
|
+
class Extractor
|
|
21
|
+
# @param archive [String] path to the gzipped executable
|
|
22
|
+
# @param dirs [Array<String>] directories to extract into, most preferred first
|
|
23
|
+
def initialize(archive, dirs)
|
|
24
|
+
@archive = archive
|
|
25
|
+
@dirs = dirs
|
|
26
|
+
@name = File.basename(archive, ".gz")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @return [String] path to the executable, extracting it if no candidate
|
|
30
|
+
# directory already holds one
|
|
31
|
+
# @raise [MissingBinaryError] if nothing is extracted yet and the archive does not exist
|
|
32
|
+
# @raise [ExtractionError] if every candidate directory fails
|
|
33
|
+
def extract
|
|
34
|
+
existing = @dirs.map { |dir| target_in(dir) }.find { |path| usable?(path) }
|
|
35
|
+
return existing if existing
|
|
36
|
+
|
|
37
|
+
unless File.file?(@archive)
|
|
38
|
+
raise MissingBinaryError,
|
|
39
|
+
"#{@archive} is missing. This copy of qpdf-binary was packaged without a binary for " \
|
|
40
|
+
"this platform; if you built it from source, run `rake binaries` before `rake build`."
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
failures = []
|
|
44
|
+
@dirs.each do |dir|
|
|
45
|
+
return write_into(dir)
|
|
46
|
+
rescue SystemCallError, IOError, Zlib::Error => e
|
|
47
|
+
failures << " #{dir}: #{e.message}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
raise ExtractionError, "could not extract #{@archive} into any of:\n#{failures.join("\n")}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def target_in(dir)
|
|
56
|
+
File.join(dir, @name)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def usable?(path)
|
|
60
|
+
File.file?(path) && File.executable?(path)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def write_into(dir)
|
|
64
|
+
FileUtils.mkdir_p(dir)
|
|
65
|
+
target = target_in(dir)
|
|
66
|
+
temp = "#{target}.#{Process.pid}.#{SecureRandom.hex(4)}.tmp"
|
|
67
|
+
|
|
68
|
+
begin
|
|
69
|
+
Zlib::GzipReader.open(@archive) do |gz|
|
|
70
|
+
File.open(temp, File::WRONLY | File::CREAT | File::EXCL, 0o700) { |out| IO.copy_stream(gz, out) }
|
|
71
|
+
end
|
|
72
|
+
File.chmod(0o755, temp)
|
|
73
|
+
File.rename(temp, target)
|
|
74
|
+
ensure
|
|
75
|
+
FileUtils.rm_f(temp)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
target
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbconfig"
|
|
4
|
+
|
|
5
|
+
module QpdfBinary
|
|
6
|
+
# Maps the running Ruby's host triple onto the platforms that have a static
|
|
7
|
+
# qpdf build.
|
|
8
|
+
#
|
|
9
|
+
# Only Linux is supported. The binaries are linked against musl, so they run
|
|
10
|
+
# on glibc and musl distributions alike, but macOS and Windows have no
|
|
11
|
+
# equivalent of a fully static executable.
|
|
12
|
+
module Platform
|
|
13
|
+
# Platforms with a binary in libexec/.
|
|
14
|
+
SUPPORTED = %w[linux-x86_64 linux-aarch64].freeze
|
|
15
|
+
|
|
16
|
+
CPU_ALIASES = {
|
|
17
|
+
"x86_64" => "x86_64",
|
|
18
|
+
"amd64" => "x86_64",
|
|
19
|
+
"x64" => "x86_64",
|
|
20
|
+
"aarch64" => "aarch64",
|
|
21
|
+
"arm64" => "aarch64"
|
|
22
|
+
}.freeze
|
|
23
|
+
private_constant :CPU_ALIASES
|
|
24
|
+
|
|
25
|
+
module_function
|
|
26
|
+
|
|
27
|
+
# @return [String] the running platform's identifier
|
|
28
|
+
# @raise [UnsupportedPlatformError] if it has no static build
|
|
29
|
+
def current
|
|
30
|
+
detect(RbConfig::CONFIG["host_os"], RbConfig::CONFIG["host_cpu"])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @param host_os [String] a value like RbConfig::CONFIG["host_os"], e.g. "linux-gnu"
|
|
34
|
+
# @param host_cpu [String] a value like RbConfig::CONFIG["host_cpu"], e.g. "x86_64"
|
|
35
|
+
# @return [String] the matching identifier from {SUPPORTED}
|
|
36
|
+
# @raise [UnsupportedPlatformError] if there is no match
|
|
37
|
+
def detect(host_os, host_cpu)
|
|
38
|
+
os = host_os.to_s.downcase
|
|
39
|
+
cpu = CPU_ALIASES[host_cpu.to_s.downcase]
|
|
40
|
+
|
|
41
|
+
unless os.start_with?("linux") && cpu
|
|
42
|
+
raise UnsupportedPlatformError,
|
|
43
|
+
"qpdf-binary has no static qpdf build for #{host_os}/#{host_cpu}. " \
|
|
44
|
+
"Supported platforms: #{SUPPORTED.join(", ")}. " \
|
|
45
|
+
"Install qpdf with your system package manager instead."
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
"linux-#{cpu}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module QpdfBinary
|
|
4
|
+
# The qpdf release this gem packages.
|
|
5
|
+
QPDF_VERSION = "12.4.2"
|
|
6
|
+
|
|
7
|
+
# SHA-256 of qpdf-QPDF_VERSION.tar.gz as published on the qpdf GitHub
|
|
8
|
+
# release. The static build refuses to compile a tarball that does not
|
|
9
|
+
# match, so bump this together with QPDF_VERSION.
|
|
10
|
+
QPDF_SOURCE_SHA256 = "8a58af5b6141319287c1883bec8bd1bd545b7567b7fc5e6ce5d25a1c85f36397"
|
|
11
|
+
|
|
12
|
+
# The gem version is the qpdf version plus a packaging revision, so
|
|
13
|
+
# 12.4.2.0 is the first build of qpdf 12.4.2 and 12.4.2.1 is a repackaging
|
|
14
|
+
# of the same qpdf (a build fix, a new platform, a wrapper change).
|
|
15
|
+
VERSION = "12.4.2.0"
|
|
16
|
+
end
|
data/lib/qpdf_binary.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "qpdf_binary/version"
|
|
4
|
+
require "qpdf_binary/errors"
|
|
5
|
+
require "qpdf_binary/platform"
|
|
6
|
+
require "qpdf_binary/extractor"
|
|
7
|
+
|
|
8
|
+
# Ships a statically linked qpdf executable inside a Ruby gem.
|
|
9
|
+
#
|
|
10
|
+
# The gem carries one gzipped binary per supported platform in +libexec/+.
|
|
11
|
+
# The first time qpdf is needed, the binary for the running platform is
|
|
12
|
+
# decompressed next to its archive, or into a per-user cache directory when
|
|
13
|
+
# the gem directory is read-only, and that copy is reused from then on.
|
|
14
|
+
#
|
|
15
|
+
# @example Run qpdf from Ruby
|
|
16
|
+
# system(QpdfBinary.path, "--check", "invoice.pdf", exception: true)
|
|
17
|
+
#
|
|
18
|
+
# @example Capture qpdf's output
|
|
19
|
+
# stdout, stderr, status = Open3.capture3(QpdfBinary.path, "--show-npages", "invoice.pdf")
|
|
20
|
+
module QpdfBinary
|
|
21
|
+
# Directory holding the gzipped binaries.
|
|
22
|
+
LIBEXEC_DIR = File.expand_path("../libexec", __dir__)
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
# Returns the path to a qpdf executable for this platform, decompressing
|
|
26
|
+
# it on first use.
|
|
27
|
+
#
|
|
28
|
+
# @return [String] absolute path to an executable qpdf binary
|
|
29
|
+
# @raise [UnsupportedPlatformError] if no build exists for this platform
|
|
30
|
+
# @raise [MissingBinaryError] if the gem was packaged without this platform's binary
|
|
31
|
+
# @raise [ExtractionError] if no candidate directory could be written to
|
|
32
|
+
def path
|
|
33
|
+
@path ||= Extractor.new(archive_path, extraction_dirs).extract
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @return [String] the identifier of the running platform, such as "linux-x86_64"
|
|
37
|
+
# @raise [UnsupportedPlatformError] if no build exists for this platform
|
|
38
|
+
def platform
|
|
39
|
+
Platform.current
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param platform [String] a platform identifier from {Platform::SUPPORTED}
|
|
43
|
+
# @return [String] path to that platform's gzipped binary
|
|
44
|
+
def archive_path(platform = self.platform)
|
|
45
|
+
File.join(LIBEXEC_DIR, "qpdf-#{platform}.gz")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Directories tried, in order, when the binary has to be decompressed.
|
|
49
|
+
#
|
|
50
|
+
# +QPDF_BINARY_CACHE_DIR+ comes first when set, which suits deployments
|
|
51
|
+
# whose gem directory and home directory are both read-only. The gem's own
|
|
52
|
+
# +libexec/+ is next, as in the wkhtmltopdf-binary gem, followed by a
|
|
53
|
+
# per-user cache under +XDG_CACHE_HOME+ (or +~/.cache+). Cache directories
|
|
54
|
+
# get a per-version subdirectory, so upgrading the gem never reuses an
|
|
55
|
+
# older qpdf.
|
|
56
|
+
#
|
|
57
|
+
# @return [Array<String>]
|
|
58
|
+
def extraction_dirs
|
|
59
|
+
dirs = []
|
|
60
|
+
override = ENV.fetch("QPDF_BINARY_CACHE_DIR", "")
|
|
61
|
+
dirs << File.join(File.expand_path(override), VERSION) unless override.empty?
|
|
62
|
+
dirs << LIBEXEC_DIR
|
|
63
|
+
user_cache = user_cache_dir
|
|
64
|
+
dirs << File.join(user_cache, "qpdf-binary", VERSION) if user_cache
|
|
65
|
+
dirs
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Forgets the memoized path. Intended for tests.
|
|
69
|
+
#
|
|
70
|
+
# @return [void]
|
|
71
|
+
def reset!
|
|
72
|
+
@path = nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
# Never falls back to a shared temporary directory: another local user
|
|
78
|
+
# could plant an executable there before this process writes its own.
|
|
79
|
+
def user_cache_dir
|
|
80
|
+
xdg = ENV.fetch("XDG_CACHE_HOME", "")
|
|
81
|
+
return xdg unless xdg.empty?
|
|
82
|
+
|
|
83
|
+
File.join(Dir.home, ".cache")
|
|
84
|
+
rescue ArgumentError
|
|
85
|
+
# Dir.home raises when HOME is unset and the user has no passwd entry.
|
|
86
|
+
nil
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
acl-libs-2.3.2-r1
|
|
2
|
+
alpine-baselayout-3.7.0-r0
|
|
3
|
+
alpine-baselayout-data-3.7.0-r0
|
|
4
|
+
alpine-keys-2.5-r0
|
|
5
|
+
alpine-release-3.22.8-r0
|
|
6
|
+
apk-tools-2.14.13-r0
|
|
7
|
+
binutils-2.44-r3
|
|
8
|
+
brotli-libs-1.1.1-r0
|
|
9
|
+
build-base-0.5-r3
|
|
10
|
+
busybox-1.37.0-r20
|
|
11
|
+
busybox-binsh-1.37.0-r20
|
|
12
|
+
c-ares-1.34.9-r0
|
|
13
|
+
ca-certificates-20261020-r0
|
|
14
|
+
ca-certificates-bundle-20261020-r0
|
|
15
|
+
cmake-3.31.7-r1
|
|
16
|
+
curl-8.14.1-r4
|
|
17
|
+
file-5.46-r2
|
|
18
|
+
fortify-headers-1.1-r5
|
|
19
|
+
g++-14.2.0-r6
|
|
20
|
+
gcc-14.2.0-r6
|
|
21
|
+
gmp-6.3.0-r3
|
|
22
|
+
isl26-0.26-r1
|
|
23
|
+
jansson-2.14.1-r0
|
|
24
|
+
libapk2-2.14.13-r0
|
|
25
|
+
libarchive-3.8.11-r0
|
|
26
|
+
libatomic-14.2.0-r6
|
|
27
|
+
libbz2-1.0.8-r6
|
|
28
|
+
libcrypto3-3.5.9-r0
|
|
29
|
+
libcurl-8.14.1-r4
|
|
30
|
+
libexpat-2.10.0-r0
|
|
31
|
+
libgcc-14.2.0-r6
|
|
32
|
+
libgomp-14.2.0-r6
|
|
33
|
+
libidn2-2.3.7-r0
|
|
34
|
+
libjpeg-turbo-3.1.0-r0
|
|
35
|
+
libjpeg-turbo-dev-3.1.0-r0
|
|
36
|
+
libjpeg-turbo-doc-3.1.0-r0
|
|
37
|
+
libjpeg-turbo-static-3.1.0-r0
|
|
38
|
+
libmagic-5.46-r2
|
|
39
|
+
libpsl-0.21.5-r3
|
|
40
|
+
libssl3-3.5.9-r0
|
|
41
|
+
libstdc++-14.2.0-r6
|
|
42
|
+
libstdc++-dev-14.2.0-r6
|
|
43
|
+
libturbojpeg-3.1.0-r0
|
|
44
|
+
libunistring-1.3-r0
|
|
45
|
+
libuv-1.51.0-r0
|
|
46
|
+
lz4-libs-1.10.0-r0
|
|
47
|
+
make-4.4.1-r3
|
|
48
|
+
mpc1-1.3.1-r1
|
|
49
|
+
mpfr4-4.2.1_p1-r0
|
|
50
|
+
musl-1.2.5-r13
|
|
51
|
+
musl-dev-1.2.5-r13
|
|
52
|
+
musl-utils-1.2.5-r13
|
|
53
|
+
nghttp2-libs-1.69.0-r0
|
|
54
|
+
openssl-dev-3.5.9-r0
|
|
55
|
+
openssl-libs-static-3.5.9-r0
|
|
56
|
+
patch-2.8-r0
|
|
57
|
+
pkgconf-2.4.3-r0
|
|
58
|
+
rhash-libs-1.4.5-r0
|
|
59
|
+
samurai-1.2-r7
|
|
60
|
+
scanelf-1.3.8-r1
|
|
61
|
+
ssl_client-1.37.0-r20
|
|
62
|
+
xz-libs-5.8.4-r0
|
|
63
|
+
zlib-1.4-r0
|
|
64
|
+
zlib-dev-1.4-r0
|
|
65
|
+
zlib-static-1.4-r0
|
|
66
|
+
zstd-libs-1.5.7-r0
|
|
Binary file
|