MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / createConverterStream

Function createConverterStream

node/cli.js:156–186  ·  view source on GitHub ↗
(converter)

Source from the content-addressed store, hash-verified

154}
155
156function createConverterStream(converter) {
157 const nativeStream = converter._createConverterStream();
158 let pendingChunk = null;
159
160 return new Transform({
161 transform(chunk, encoding, callback) {
162 try {
163 const input = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding);
164 if (pendingChunk === null) {
165 pendingChunk = Buffer.from(input);
166 callback();
167 return;
168 }
169 const output = nativeStream.convertChunk(pendingChunk);
170 pendingChunk = Buffer.from(input);
171 callback(null, output);
172 } catch (error) {
173 callback(error);
174 }
175 },
176 flush(callback) {
177 try {
178 callback(null, pendingChunk === null
179 ? nativeStream.finish()
180 : nativeStream.finish(pendingChunk));
181 } catch (error) {
182 callback(error);
183 }
184 },
185 });
186}
187
188function isSameFile(inputFileName, outputFileName) {
189 if (!inputFileName || !outputFileName) {

Callers 1

convertStreamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected