| 154 | } |
| 155 | |
| 156 | function 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 | |
| 188 | function isSameFile(inputFileName, outputFileName) { |
| 189 | if (!inputFileName || !outputFileName) { |