MCPcopy Create free account
hub / github.com/p2r3/convert / doConvert

Method doConvert

src/handlers/textToSource.ts:148–174  ·  view source on GitHub ↗
(
    inputFiles: FileData[],
    inputFormat: FileFormat,
    outputFormat: FileFormat
  )

Source from the content-addressed store, hash-verified

146 }
147
148 async doConvert (
149 inputFiles: FileData[],
150 inputFormat: FileFormat,
151 outputFormat: FileFormat
152 ): Promise<FileData[]> {
153 const outputFiles: FileData[] = [];
154 const converterEntry = textToSourceHandler.converters.find(
155 ([format]) => format.internal === outputFormat.internal
156 );
157
158 if (!converterEntry) {
159 throw new Error(`could not find a textToSource converter to convert to ${outputFormat.mime}`);
160 }
161
162 const [, converter] = converterEntry;
163
164 for (const inputFile of inputFiles) {
165 const text = new TextDecoder().decode(inputFile.bytes).replaceAll(/\r?\n/g, "\n");
166
167 const converted = converter(text);
168
169 const bytes = new TextEncoder().encode(converted);
170 const name = inputFile.name.replace(/\.txt$/i, `.${outputFormat.extension}`);
171 outputFiles.push({ bytes, name });
172 }
173 return outputFiles;
174 }
175
176}
177

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected