215
}
216
217
>
export async function toEncodeReadable(readable: Readable<string>, encoding: string, options?: { addBOM?: boolean }): Promise<VSBufferReadable> {
encoding.ts
218
>
const iconv = await importAMDNodeModule<typeof import('@vscode/iconv-lite-umd')>('@vscode/iconv-lite-umd', 'lib/iconv-lite-umd.js');
219
>
const encoder = iconv.getEncoder(toNodeEncoding(encoding), options);
220
>
221
>
let bytesWritten = false;
222
>
let done = false;
223
>
224
>
return {
225
>
read() {
226
>
if (done) {
227
return null;
228
}
230
>
const chunk = readable.read();
231
>
if (typeof chunk !== 'string') {
232
>
done = true;
233
>
234
>
// If we are instructed to add a BOM but we detect that no
235
>
// bytes have been written, we must ensure to return the BOM
236
>
// ourselves so that we comply with the contract.
237
>
if (!bytesWritten && options?.addBOM) {
238
switch (encoding) {
239
case UTF8: