MCPcopy
hub / github.com/lovell/sharp / toFile

Function toFile

lib/output.mjs:73–94  ·  view source on GitHub ↗

* Write output image data to a file. * * If an explicit output format is not selected, it will be inferred from the extension, * with JPEG, PNG, WebP, AVIF, TIFF, GIF, DZI, and libvips' V format supported. * Note that raw pixel data is only supported for buffer output. * * By default all metad

(fileOut, callback)

Source from the content-addressed store, hash-verified

71 * @throws {Error} Invalid parameters
72 */
73function toFile (fileOut, callback) {
74 let err;
75 if (!is.string(fileOut)) {
76 err = new Error('Missing output file path');
77 } else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
78 err = new Error('Cannot use same file for input and output');
79 } else if (jp2Regex.test(path.extname(fileOut)) && !this.constructor.format.jp2.output.file) {
80 err = errJp2Save();
81 }
82 if (err) {
83 if (is.fn(callback)) {
84 callback(err);
85 } else {
86 return Promise.reject(err);
87 }
88 } else {
89 this.options.fileOut = fileOut;
90 const stack = Error();
91 return this._pipeline(callback, stack);
92 }
93 return this;
94}
95
96/**
97 * Write output to a Buffer.

Callers

nothing calls this directly

Calls 1

errJp2SaveFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…