Skip to content

Commit 3cf529d

Browse files
author
Benjamin Pasero
committed
remove unused code
1 parent 8c2f360 commit 3cf529d

3 files changed

Lines changed: 1 addition & 83 deletions

File tree

src/vs/base/node/encoding.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ export function decode(buffer: Buffer, encoding: string): string {
142142
return iconv.decode(buffer, toNodeEncoding(encoding));
143143
}
144144

145-
export function encode(content: string | Buffer, encoding: string, options?: { addBOM?: boolean }): Buffer {
146-
return iconv.encode(content as string /* TODO report into upstream typings */, toNodeEncoding(encoding), options);
147-
}
148-
149145
export function encodingExists(encoding: string): boolean {
150146
return iconv.encodingExists(toNodeEncoding(encoding));
151147
}

src/vs/base/node/pfs.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { promisify } from 'util';
1414
import { isRootOrDriveLetter } from 'vs/base/common/extpath';
1515
import { generateUuid } from 'vs/base/common/uuid';
1616
import { normalizeNFC } from 'vs/base/common/normalization';
17-
import { encode } from 'vs/base/node/encoding';
1817

1918
// See https://github.com/Microsoft/vscode/issues/30180
2019
const WIN32_MAX_FILE_SIZE = 300 * 1024 * 1024; // 300 MB
@@ -320,10 +319,6 @@ function ensureWriteFileQueue(queueKey: string): Queue<void> {
320319
export interface IWriteFileOptions {
321320
mode?: number;
322321
flag?: string;
323-
encoding?: {
324-
charset: string;
325-
addBOM: boolean;
326-
};
327322
}
328323

329324
interface IEnsuredWriteFileOptions extends IWriteFileOptions {
@@ -339,10 +334,6 @@ let canFlush = true;
339334
//
340335
// See https://github.com/nodejs/node/blob/v5.10.0/lib/fs.js#L1194
341336
function doWriteFileAndFlush(path: string, data: string | Buffer | Uint8Array, options: IEnsuredWriteFileOptions, callback: (error: Error | null) => void): void {
342-
if (options.encoding) {
343-
data = encode(data instanceof Uint8Array ? Buffer.from(data) : data, options.encoding.charset, { addBOM: options.encoding.addBOM });
344-
}
345-
346337
if (!canFlush) {
347338
return fs.writeFile(path, data, { mode: options.mode, flag: options.flag }, callback);
348339
}
@@ -378,10 +369,6 @@ function doWriteFileAndFlush(path: string, data: string | Buffer | Uint8Array, o
378369
export function writeFileSync(path: string, data: string | Buffer, options?: IWriteFileOptions): void {
379370
const ensuredOptions = ensureWriteOptions(options);
380371

381-
if (ensuredOptions.encoding) {
382-
data = encode(data, ensuredOptions.encoding.charset, { addBOM: ensuredOptions.encoding.addBOM });
383-
}
384-
385372
if (!canFlush) {
386373
return fs.writeFileSync(path, data, { mode: ensuredOptions.mode, flag: ensuredOptions.flag });
387374
}
@@ -413,8 +400,7 @@ function ensureWriteOptions(options?: IWriteFileOptions): IEnsuredWriteFileOptio
413400

414401
return {
415402
mode: typeof options.mode === 'number' ? options.mode : 0o666,
416-
flag: typeof options.flag === 'string' ? options.flag : 'w',
417-
encoding: options.encoding
403+
flag: typeof options.flag === 'string' ? options.flag : 'w'
418404
};
419405
}
420406

src/vs/base/node/stream.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as fs from 'fs';
76
import { VSBufferReadableStream, VSBufferReadable, VSBuffer } from 'vs/base/common/buffer';
87
import { Readable } from 'stream';
98
import { isUndefinedOrNull } from 'vs/base/common/types';
109
import { UTF8, UTF8_with_bom, UTF8_BOM, UTF16be, UTF16le_BOM, UTF16be_BOM, UTF16le, UTF_ENCODING } from 'vs/base/node/encoding';
1110

12-
/**
13-
* Reads a file until a matching string is found.
14-
*
15-
* @param file The file to read.
16-
* @param matchingString The string to search for.
17-
* @param chunkBytes The number of bytes to read each iteration.
18-
* @param maximumBytesToRead The maximum number of bytes to read before giving up.
19-
* @param callback The finished callback.
20-
*/
21-
export function readToMatchingString(file: string, matchingString: string, chunkBytes: number, maximumBytesToRead: number): Promise<string | null> {
22-
return new Promise<string | null>((resolve, reject) =>
23-
fs.open(file, 'r', null, (err, fd) => {
24-
if (err) {
25-
return reject(err);
26-
}
27-
28-
function end(err: Error | null, result: string | null): void {
29-
fs.close(fd, closeError => {
30-
if (closeError) {
31-
return reject(closeError);
32-
}
33-
34-
if (err && (<any>err).code === 'EISDIR') {
35-
return reject(err); // we want to bubble this error up (file is actually a folder)
36-
}
37-
38-
return resolve(result);
39-
});
40-
}
41-
42-
const buffer = Buffer.allocUnsafe(maximumBytesToRead);
43-
let offset = 0;
44-
45-
function readChunk(): void {
46-
fs.read(fd, buffer, offset, chunkBytes, null, (err, bytesRead) => {
47-
if (err) {
48-
return end(err, null);
49-
}
50-
51-
if (bytesRead === 0) {
52-
return end(null, null);
53-
}
54-
55-
offset += bytesRead;
56-
57-
const newLineIndex = buffer.indexOf(matchingString);
58-
if (newLineIndex >= 0) {
59-
return end(null, buffer.toString('utf8').substr(0, newLineIndex));
60-
}
61-
62-
if (offset >= maximumBytesToRead) {
63-
return end(new Error(`Could not find ${matchingString} in first ${maximumBytesToRead} bytes of ${file}`), null);
64-
}
65-
66-
return readChunk();
67-
});
68-
}
69-
70-
readChunk();
71-
})
72-
);
73-
}
74-
7511
export function streamToNodeReadable(stream: VSBufferReadableStream): Readable {
7612
return new class extends Readable {
7713
private listening = false;

0 commit comments

Comments
 (0)