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

Function processFileByFormat

optimize.js:133–161  ·  view source on GitHub ↗
({ fileBuffer, config, isLossless })

Source from the content-addressed store, hash-verified

131}
132
133async function processFileByFormat({ fileBuffer, config, isLossless }) {
134 const imageMetadata = await parseImageMetadata(fileBuffer);
135
136 if (!imageMetadata.format) {
137 throw new Error('Unknown file format');
138 }
139
140 switch (imageMetadata.format) {
141 case 'jpeg': {
142 return processJpeg({ fileBuffer, config, isLossless });
143 }
144
145 case 'png': {
146 return processPng({ fileBuffer, config, isLossless });
147 }
148
149 case 'gif': {
150 return processGif({ fileBuffer, config, isLossless });
151 }
152
153 case 'svg': {
154 return processSvg({ fileBuffer, config });
155 }
156
157 default: {
158 throw new Error(`Unsupported image format: "${imageMetadata.format}"`);
159 }
160 }
161}
162
163async function processJpeg({ fileBuffer, config, isLossless }) {
164 const sharpImage = sharp(fileBuffer)

Callers 1

processFileFunction · 0.85

Calls 5

parseImageMetadataFunction · 0.90
processJpegFunction · 0.85
processPngFunction · 0.85
processGifFunction · 0.85
processSvgFunction · 0.85

Tested by

no test coverage detected