MCPcopy Create free account
hub / github.com/343dev/optimizt / pipe

Function pipe

optimize.js:226–252  ·  view source on GitHub ↗
({ command, commandOptions, inputBuffer })

Source from the content-addressed store, hash-verified

224}
225
226function pipe({ command, commandOptions, inputBuffer }) {
227 return new Promise((resolve, reject) => {
228 const process = spawn(command, commandOptions);
229
230 process.stdin.write(inputBuffer);
231 process.stdin.end();
232
233 const stdoutChunks = [];
234 process.stdout.on('data', (chunk) => {
235 stdoutChunks.push(chunk);
236 });
237
238 process.on('error', (error) => {
239 reject(new Error(`Error processing image: ${error.message}`));
240 });
241
242 process.on('close', (code) => {
243 if (code !== 0) {
244 reject(new Error(`Image optimization process exited with code ${code}`));
245 return;
246 }
247
248 const processedFileBuffer = Buffer.concat(stdoutChunks);
249 resolve(processedFileBuffer);
250 });
251 });
252}

Callers 2

processJpegFunction · 0.85
processGifFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected