sharp 0.35.0-rc.3 → 0.35.0-rc.5

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.
package/dist/sharp.cjs ADDED
@@ -0,0 +1,162 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ // Inspects the runtime environment and exports the relevant sharp.node binary
7
+
8
+ const { familySync, versionSync } = require("detect-libc");
9
+
10
+ const libvips = require("./libvips.cjs");
11
+ const pkg = require('../package.json');
12
+
13
+ const { version } = pkg;
14
+
15
+ const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = libvips;
16
+ const runtimePlatform = runtimePlatformArch();
17
+
18
+ /* node:coverage disable */
19
+
20
+ let sharp;
21
+ const errors = [];
22
+ try {
23
+ sharp = require(`../src/build/Release/sharp-${runtimePlatform}-${version}.node`);
24
+ } catch (err) {
25
+ errors.push(err);
26
+ }
27
+ if (!sharp) {
28
+ try {
29
+ sharp = require(`../src/build/Release/sharp-wasm32-${version}.node`);
30
+ } catch (err) {
31
+ errors.push(err);
32
+ }
33
+ }
34
+ if (!sharp) {
35
+ try {
36
+ switch (runtimePlatform) {
37
+ case "darwin-arm64":
38
+ sharp = require("@img/sharp-darwin-arm64/sharp.node");
39
+ break;
40
+ case "darwin-x64":
41
+ sharp = require("@img/sharp-darwin-x64/sharp.node");
42
+ break;
43
+ case "linux-arm":
44
+ sharp = require("@img/sharp-linux-arm/sharp.node");
45
+ break;
46
+ case "linux-arm64":
47
+ sharp = require("@img/sharp-linux-arm64/sharp.node");
48
+ break;
49
+ case "linux-ppc64":
50
+ sharp = require("@img/sharp-linux-ppc64/sharp.node");
51
+ break;
52
+ case "linux-riscv64":
53
+ sharp = require("@img/sharp-linux-riscv64/sharp.node");
54
+ break;
55
+ case "linux-s390x":
56
+ sharp = require("@img/sharp-linux-s390x/sharp.node");
57
+ break;
58
+ case "linux-x64":
59
+ sharp = require("@img/sharp-linux-x64/sharp.node");
60
+ break;
61
+ case "linuxmusl-arm64":
62
+ sharp = require("@img/sharp-linuxmusl-arm64/sharp.node");
63
+ break;
64
+ case "linuxmusl-x64":
65
+ sharp = require("@img/sharp-linuxmusl-x64/sharp.node");
66
+ break;
67
+ case "win32-arm64":
68
+ sharp = require("@img/sharp-win32-arm64/sharp.node");
69
+ break;
70
+ case "win32-ia32":
71
+ sharp = require("@img/sharp-win32-ia32/sharp.node");
72
+ break;
73
+ case "win32-x64":
74
+ sharp = require("@img/sharp-win32-x64/sharp.node");
75
+ break;
76
+ case "freebsd-arm64":
77
+ case "freebsd-x64":
78
+ sharp = require("@img/sharp-freebsd-wasm32/sharp.node");
79
+ break;
80
+ case "linux-wasm32":
81
+ sharp = require("@img/sharp-webcontainers-wasm32/sharp.node");
82
+ break;
83
+ default:
84
+ sharp = require("@img/sharp-wasm32/sharp.node");
85
+ break;
86
+ }
87
+ if (["linux-x64", "linuxmusl-x64"].includes(runtimePlatform) && !sharp._isUsingX64V2()) {
88
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
89
+ err.code = "Unsupported CPU";
90
+ errors.push(err);
91
+ sharp = null;
92
+ }
93
+ } catch (err) {
94
+ errors.push(err);
95
+ }
96
+ }
97
+
98
+ if (!sharp) {
99
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
100
+
101
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
102
+ errors.forEach((err) => {
103
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
104
+ help.push(`${err.code}: ${err.message}`);
105
+ }
106
+ });
107
+ const messages = errors.map((err) => err.message).join(" ");
108
+ help.push("Possible solutions:");
109
+ // Common error messages
110
+ if (isUnsupportedNodeRuntime()) {
111
+ const { found, expected } = isUnsupportedNodeRuntime();
112
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
113
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
114
+ const [os, cpu] = runtimePlatform.split("-");
115
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
116
+ help.push(
117
+ "- Ensure optional dependencies can be installed:",
118
+ " npm install --include=optional sharp",
119
+ "- Ensure your package manager supports multi-platform installation:",
120
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
121
+ "- Add platform-specific dependencies:",
122
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
123
+ );
124
+ } else {
125
+ help.push(
126
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
127
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
128
+ "- Add WebAssembly-based dependencies:",
129
+ " npm install sharp @img/sharp-wasm32",
130
+ );
131
+ }
132
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
133
+ try {
134
+ const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
135
+ const libcFound = `${familySync()} ${versionSync()}`;
136
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
137
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
138
+ } catch (_errEngines) {}
139
+ }
140
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
141
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
142
+ }
143
+ if (isMacOs && /Incompatible library version/.test(messages)) {
144
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
145
+ }
146
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
147
+ help.push("- Run Node.js without using the --no-addons flag");
148
+ }
149
+ // Link to installation docs
150
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
151
+ help.push(
152
+ "- Using the canvas package on Windows?",
153
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
154
+ "- Check for outdated versions of sharp in the dependency tree:",
155
+ " npm ls sharp",
156
+ );
157
+ }
158
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
159
+ throw new Error(help.join("\n"));
160
+ }
161
+
162
+ module.exports = sharp;
package/dist/sharp.mjs ADDED
@@ -0,0 +1,164 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ // Inspects the runtime environment and exports the relevant sharp.node binary
7
+
8
+ import { createRequire } from "node:module"
9
+ import { familySync, versionSync } from "detect-libc";
10
+
11
+ import libvips from "./libvips.mjs";
12
+ import pkg from '../package.json' with { type: 'json' };
13
+
14
+ const require = createRequire(import.meta.url);
15
+ const { version } = pkg;
16
+
17
+ const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = libvips;
18
+ const runtimePlatform = runtimePlatformArch();
19
+
20
+ /* node:coverage disable */
21
+
22
+ let sharp;
23
+ const errors = [];
24
+ try {
25
+ sharp = require(`../src/build/Release/sharp-${runtimePlatform}-${version}.node`);
26
+ } catch (err) {
27
+ errors.push(err);
28
+ }
29
+ if (!sharp) {
30
+ try {
31
+ sharp = require(`../src/build/Release/sharp-wasm32-${version}.node`);
32
+ } catch (err) {
33
+ errors.push(err);
34
+ }
35
+ }
36
+ if (!sharp) {
37
+ try {
38
+ switch (runtimePlatform) {
39
+ case "darwin-arm64":
40
+ sharp = require("@img/sharp-darwin-arm64/sharp.node");
41
+ break;
42
+ case "darwin-x64":
43
+ sharp = require("@img/sharp-darwin-x64/sharp.node");
44
+ break;
45
+ case "linux-arm":
46
+ sharp = require("@img/sharp-linux-arm/sharp.node");
47
+ break;
48
+ case "linux-arm64":
49
+ sharp = require("@img/sharp-linux-arm64/sharp.node");
50
+ break;
51
+ case "linux-ppc64":
52
+ sharp = require("@img/sharp-linux-ppc64/sharp.node");
53
+ break;
54
+ case "linux-riscv64":
55
+ sharp = require("@img/sharp-linux-riscv64/sharp.node");
56
+ break;
57
+ case "linux-s390x":
58
+ sharp = require("@img/sharp-linux-s390x/sharp.node");
59
+ break;
60
+ case "linux-x64":
61
+ sharp = require("@img/sharp-linux-x64/sharp.node");
62
+ break;
63
+ case "linuxmusl-arm64":
64
+ sharp = require("@img/sharp-linuxmusl-arm64/sharp.node");
65
+ break;
66
+ case "linuxmusl-x64":
67
+ sharp = require("@img/sharp-linuxmusl-x64/sharp.node");
68
+ break;
69
+ case "win32-arm64":
70
+ sharp = require("@img/sharp-win32-arm64/sharp.node");
71
+ break;
72
+ case "win32-ia32":
73
+ sharp = require("@img/sharp-win32-ia32/sharp.node");
74
+ break;
75
+ case "win32-x64":
76
+ sharp = require("@img/sharp-win32-x64/sharp.node");
77
+ break;
78
+ case "freebsd-arm64":
79
+ case "freebsd-x64":
80
+ sharp = require("@img/sharp-freebsd-wasm32/sharp.node");
81
+ break;
82
+ case "linux-wasm32":
83
+ sharp = require("@img/sharp-webcontainers-wasm32/sharp.node");
84
+ break;
85
+ default:
86
+ sharp = require("@img/sharp-wasm32/sharp.node");
87
+ break;
88
+ }
89
+ if (["linux-x64", "linuxmusl-x64"].includes(runtimePlatform) && !sharp._isUsingX64V2()) {
90
+ const err = new Error("Prebuilt binaries for Linux x64 require v2 microarchitecture");
91
+ err.code = "Unsupported CPU";
92
+ errors.push(err);
93
+ sharp = null;
94
+ }
95
+ } catch (err) {
96
+ errors.push(err);
97
+ }
98
+ }
99
+
100
+ if (!sharp) {
101
+ const [isLinux, isMacOs, isWindows] = ["linux", "darwin", "win32"].map((os) => runtimePlatform.startsWith(os));
102
+
103
+ const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
104
+ errors.forEach((err) => {
105
+ if (!err.code.endsWith("MODULE_NOT_FOUND")) {
106
+ help.push(`${err.code}: ${err.message}`);
107
+ }
108
+ });
109
+ const messages = errors.map((err) => err.message).join(" ");
110
+ help.push("Possible solutions:");
111
+ // Common error messages
112
+ if (isUnsupportedNodeRuntime()) {
113
+ const { found, expected } = isUnsupportedNodeRuntime();
114
+ help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
115
+ } else if (prebuiltPlatforms.includes(runtimePlatform)) {
116
+ const [os, cpu] = runtimePlatform.split("-");
117
+ const libc = os.endsWith("musl") ? " --libc=musl" : "";
118
+ help.push(
119
+ "- Ensure optional dependencies can be installed:",
120
+ " npm install --include=optional sharp",
121
+ "- Ensure your package manager supports multi-platform installation:",
122
+ " See https://sharp.pixelplumbing.com/install#cross-platform",
123
+ "- Add platform-specific dependencies:",
124
+ ` npm install --os=${os.replace("musl", "")}${libc} --cpu=${cpu} sharp`,
125
+ );
126
+ } else {
127
+ help.push(
128
+ `- Manually install libvips >= ${minimumLibvipsVersion}`,
129
+ " See https://sharp.pixelplumbing.com/install#building-from-source",
130
+ "- Add WebAssembly-based dependencies:",
131
+ " npm install sharp @img/sharp-wasm32",
132
+ );
133
+ }
134
+ if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
135
+ try {
136
+ const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
137
+ const libcFound = `${familySync()} ${versionSync()}`;
138
+ const libcRequires = `${config.musl ? "musl" : "glibc"} ${config.musl || config.glibc}`;
139
+ help.push("- Update your OS:", ` Found ${libcFound}`, ` Requires ${libcRequires}`);
140
+ } catch (_errEngines) {}
141
+ }
142
+ if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
143
+ help.push("- Remove the Node.js Snap, which does not support native modules", " snap remove node");
144
+ }
145
+ if (isMacOs && /Incompatible library version/.test(messages)) {
146
+ help.push("- Update Homebrew:", " brew update && brew upgrade vips");
147
+ }
148
+ if (errors.some((err) => err.code === "ERR_DLOPEN_DISABLED")) {
149
+ help.push("- Run Node.js without using the --no-addons flag");
150
+ }
151
+ // Link to installation docs
152
+ if (isWindows && /The specified procedure could not be found/.test(messages)) {
153
+ help.push(
154
+ "- Using the canvas package on Windows?",
155
+ " See https://sharp.pixelplumbing.com/install#canvas-and-windows",
156
+ "- Check for outdated versions of sharp in the dependency tree:",
157
+ " npm ls sharp",
158
+ );
159
+ }
160
+ help.push("- Consult the installation documentation:", " See https://sharp.pixelplumbing.com/install");
161
+ throw new Error(help.join("\n"));
162
+ }
163
+
164
+ export default sharp;
@@ -0,0 +1,293 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ const events = require('node:events');
7
+ const { availableParallelism } = require("node:os");
8
+ const detectLibc = require('detect-libc');
9
+
10
+ const is = require('./is.cjs');
11
+ const libvips = require('./libvips.cjs');
12
+ const sharp = require('./sharp.cjs');
13
+ const pkg = require("../package.json");
14
+
15
+ const runtimePlatform = libvips.runtimePlatformArch();
16
+ const libvipsVersion = sharp.libvipsVersion();
17
+
18
+ /**
19
+ * An Object containing nested boolean values representing the available input and output formats/methods.
20
+ * @member
21
+ * @example
22
+ * console.log(sharp.format);
23
+ * @returns {Object}
24
+ */
25
+ const format = sharp.format();
26
+ format.heif.output.alias = ['avif', 'heic'];
27
+ format.jpeg.output.alias = ['jpe', 'jpg'];
28
+ format.tiff.output.alias = ['tif'];
29
+ format.jp2.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
30
+
31
+ /**
32
+ * An Object containing the available interpolators and their proper values
33
+ * @readonly
34
+ * @enum {string}
35
+ */
36
+ const interpolators = {
37
+ /** [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. */
38
+ nearest: 'nearest',
39
+ /** [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. */
40
+ bilinear: 'bilinear',
41
+ /** [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). */
42
+ bicubic: 'bicubic',
43
+ /** [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. */
44
+ locallyBoundedBicubic: 'lbb',
45
+ /** [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. */
46
+ nohalo: 'nohalo',
47
+ /** [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. */
48
+ vertexSplitQuadraticBasisSpline: 'vsqbs'
49
+ };
50
+
51
+ /**
52
+ * An Object containing the version numbers of sharp, libvips
53
+ * and (when using prebuilt binaries) its dependencies.
54
+ *
55
+ * @member
56
+ * @example
57
+ * console.log(sharp.versions);
58
+ */
59
+ let versions = {
60
+ vips: libvipsVersion.semver
61
+ };
62
+ /* node:coverage ignore next 15 */
63
+ if (!libvipsVersion.isGlobal) {
64
+ if (!libvipsVersion.isWasm) {
65
+ try {
66
+ versions = require(`@img/sharp-${runtimePlatform}/versions`);
67
+ } catch (_) {
68
+ try {
69
+ versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
70
+ } catch (_) {}
71
+ }
72
+ } else {
73
+ try {
74
+ versions = require('@img/sharp-wasm32/versions');
75
+ } catch (_) {}
76
+ }
77
+ }
78
+ versions.sharp = pkg.version;
79
+
80
+ /* node:coverage ignore next 5 */
81
+ if (versions.heif && format.heif) {
82
+ // Prebuilt binaries provide AV1
83
+ format.heif.input.fileSuffix = ['.avif'];
84
+ format.heif.output.alias = ['avif'];
85
+ }
86
+
87
+ /**
88
+ * Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
89
+ * Existing entries in the cache will be trimmed after any change in limits.
90
+ * This method always returns cache statistics,
91
+ * useful for determining how much working memory is required for a particular task.
92
+ *
93
+ * @example
94
+ * const stats = sharp.cache();
95
+ * @example
96
+ * sharp.cache( { items: 200 } );
97
+ * sharp.cache( { files: 0 } );
98
+ * sharp.cache(false);
99
+ *
100
+ * @param {Object|boolean} [options=true] - Object with the following attributes, or boolean where true uses default cache settings and false removes all caching
101
+ * @param {number} [options.memory=50] - is the maximum memory in MB to use for this cache
102
+ * @param {number} [options.files=20] - is the maximum number of files to hold open
103
+ * @param {number} [options.items=100] - is the maximum number of operations to cache
104
+ * @returns {Object}
105
+ */
106
+ function cache (options) {
107
+ if (is.bool(options)) {
108
+ if (options) {
109
+ // Default cache settings of 50MB, 20 files, 100 items
110
+ return sharp.cache(50, 20, 100);
111
+ } else {
112
+ return sharp.cache(0, 0, 0);
113
+ }
114
+ } else if (is.object(options)) {
115
+ return sharp.cache(options.memory, options.files, options.items);
116
+ } else {
117
+ return sharp.cache();
118
+ }
119
+ }
120
+ cache(true);
121
+
122
+ /**
123
+ * Gets or, when a concurrency is provided, sets
124
+ * the maximum number of threads _libvips_ should use to process _each image_.
125
+ * These are from a thread pool managed by glib,
126
+ * which helps avoid the overhead of creating new threads.
127
+ *
128
+ * This method always returns the current concurrency.
129
+ *
130
+ * The default value is the number of CPU cores,
131
+ * except when using glibc-based Linux without jemalloc,
132
+ * where the default is `1` to help reduce memory fragmentation.
133
+ *
134
+ * A value of `0` will reset this to the number of CPU cores.
135
+ *
136
+ * Some image format libraries spawn additional threads,
137
+ * e.g. libaom manages its own 4 threads when encoding AVIF images,
138
+ * and these are independent of the value set here.
139
+ *
140
+ * :::note
141
+ * Further {@link /performance/ control over performance} is available.
142
+ * :::
143
+ *
144
+ * @example
145
+ * const threads = sharp.concurrency(); // 4
146
+ * sharp.concurrency(2); // 2
147
+ * sharp.concurrency(0); // 4
148
+ *
149
+ * @param {number} [concurrency]
150
+ * @returns {number} concurrency
151
+ */
152
+ function concurrency (concurrency) {
153
+ return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
154
+ }
155
+ /* node:coverage ignore next 7 */
156
+ if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
157
+ // Reduce default concurrency to 1 when using glibc memory allocator
158
+ sharp.concurrency(1);
159
+ } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
160
+ // Reduce default concurrency when musl thread over-subscription detected
161
+ sharp.concurrency(availableParallelism());
162
+ }
163
+
164
+ /**
165
+ * An EventEmitter that emits a `change` event when a task is either:
166
+ * - queued, waiting for _libuv_ to provide a worker thread
167
+ * - complete
168
+ * @member
169
+ * @example
170
+ * sharp.queue.on('change', function(queueLength) {
171
+ * console.log('Queue contains ' + queueLength + ' task(s)');
172
+ * });
173
+ */
174
+ const queue = new events.EventEmitter();
175
+
176
+ /**
177
+ * Provides access to internal task counters.
178
+ * - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
179
+ * - process is the number of resize tasks currently being processed.
180
+ *
181
+ * @example
182
+ * const counters = sharp.counters(); // { queue: 2, process: 4 }
183
+ *
184
+ * @returns {Object}
185
+ */
186
+ function counters () {
187
+ return sharp.counters();
188
+ }
189
+
190
+ /**
191
+ * Get and set use of SIMD vector unit instructions.
192
+ * Requires libvips to have been compiled with highway support.
193
+ *
194
+ * Improves the performance of `resize`, `blur` and `sharpen` operations
195
+ * by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
196
+ *
197
+ * @example
198
+ * const simd = sharp.simd();
199
+ * // simd is `true` if the runtime use of highway is currently enabled
200
+ * @example
201
+ * const simd = sharp.simd(false);
202
+ * // prevent libvips from using highway at runtime
203
+ *
204
+ * @param {boolean} [simd=true]
205
+ * @returns {boolean}
206
+ */
207
+ function simd (simd) {
208
+ return sharp.simd(is.bool(simd) ? simd : null);
209
+ }
210
+
211
+ /**
212
+ * Block libvips operations at runtime.
213
+ *
214
+ * This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
215
+ * which when set will block all "untrusted" operations.
216
+ *
217
+ * @since 0.32.4
218
+ *
219
+ * @example <caption>Block all TIFF input.</caption>
220
+ * sharp.block({
221
+ * operation: ['VipsForeignLoadTiff']
222
+ * });
223
+ *
224
+ * @param {Object} options
225
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to block.
226
+ */
227
+ function block (options) {
228
+ if (is.object(options)) {
229
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
230
+ sharp.block(options.operation, true);
231
+ } else {
232
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
233
+ }
234
+ } else {
235
+ throw is.invalidParameterError('options', 'object', options);
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Unblock libvips operations at runtime.
241
+ *
242
+ * This is useful for defining a list of allowed operations.
243
+ *
244
+ * @since 0.32.4
245
+ *
246
+ * @example <caption>Block all input except WebP from the filesystem.</caption>
247
+ * sharp.block({
248
+ * operation: ['VipsForeignLoad']
249
+ * });
250
+ * sharp.unblock({
251
+ * operation: ['VipsForeignLoadWebpFile']
252
+ * });
253
+ *
254
+ * @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
255
+ * sharp.block({
256
+ * operation: ['VipsForeignLoad']
257
+ * });
258
+ * sharp.unblock({
259
+ * operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
260
+ * });
261
+ *
262
+ * @param {Object} options
263
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
264
+ */
265
+ function unblock (options) {
266
+ if (is.object(options)) {
267
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
268
+ sharp.block(options.operation, false);
269
+ } else {
270
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
271
+ }
272
+ } else {
273
+ throw is.invalidParameterError('options', 'object', options);
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Decorate the Sharp class with utility-related functions.
279
+ * @module Sharp
280
+ * @private
281
+ */
282
+ module.exports = (Sharp) => {
283
+ Sharp.cache = cache;
284
+ Sharp.concurrency = concurrency;
285
+ Sharp.counters = counters;
286
+ Sharp.simd = simd;
287
+ Sharp.format = format;
288
+ Sharp.interpolators = interpolators;
289
+ Sharp.versions = versions;
290
+ Sharp.queue = queue;
291
+ Sharp.block = block;
292
+ Sharp.unblock = unblock;
293
+ };