提交 b57003f3 编写于 作者: B Benjamin Pasero

NodeBuffer => Buffer

上级 e2b722d2
......@@ -9,7 +9,7 @@ import * as jschardet from 'jschardet';
jschardet.Constants.MINIMUM_THRESHOLD = 0.2;
function detectEncodingByBOM(buffer: NodeBuffer): string | null {
function detectEncodingByBOM(buffer: Buffer): string | null {
if (!buffer || buffer.length < 2) {
return null;
}
......
......@@ -3,7 +3,7 @@ declare module 'jschardet' {
encoding: string,
confidence: number
}
export function detect(buffer: NodeBuffer): IDetectedMap;
export function detect(buffer: Buffer): IDetectedMap;
export const Constants: {
MINIMUM_THRESHOLD: number,
......
......@@ -23,7 +23,7 @@ export class LineDecoder {
this.remaining = null;
}
public write(buffer: NodeBuffer): string[] {
public write(buffer: Buffer): string[] {
var result: string[] = [];
var value = this.remaining
? this.remaining + this.stringDecoder.write(buffer)
......
......@@ -6,9 +6,9 @@
/// <reference path='./node.d.ts'/>
declare module 'iconv-lite' {
export function decode(buffer: NodeBuffer, encoding: string): string;
export function decode(buffer: Buffer, encoding: string): string;
export function encode(content: string | NodeBuffer, encoding: string, options?: { addBOM?: boolean }): NodeBuffer;
export function encode(content: string | Buffer, encoding: string, options?: { addBOM?: boolean }): Buffer;
export function encodingExists(encoding: string): boolean;
......
......@@ -3,7 +3,7 @@ declare module 'jschardet' {
encoding: string,
confidence: number
}
export function detect(buffer: NodeBuffer): IDetectedMap;
export function detect(buffer: Buffer): IDetectedMap;
export const Constants: {
MINIMUM_THRESHOLD: number,
......
......@@ -32,7 +32,7 @@ export function checksum(path: string, sha1hash: string): TPromise<void> {
input.once('error', done);
input.once('end', done);
hashStream.once('error', done);
hashStream.once('data', (data: NodeBuffer) => done(null, data.toString('hex')));
hashStream.once('data', (data: Buffer) => done(null, data.toString('hex')));
});
return promise.then(hash => {
......
......@@ -25,7 +25,7 @@ export class LineDecoder {
this.remaining = null;
}
public write(buffer: NodeBuffer): string[] {
public write(buffer: Buffer): string[] {
let result: string[] = [];
let value = this.remaining
? this.remaining + this.stringDecoder.write(buffer)
......
......@@ -119,11 +119,11 @@ export function bomLength(encoding: string): number {
return 0;
}
export function decode(buffer: NodeBuffer, encoding: string): string {
export function decode(buffer: Buffer, encoding: string): string {
return iconv.decode(buffer, toNodeEncoding(encoding));
}
export function encode(content: string | NodeBuffer, encoding: string, options?: { addBOM?: boolean }): NodeBuffer {
export function encode(content: string | Buffer, encoding: string, options?: { addBOM?: boolean }): Buffer {
return iconv.encode(content, toNodeEncoding(encoding), options);
}
......@@ -147,7 +147,7 @@ function toNodeEncoding(enc: string): string {
return enc;
}
export function detectEncodingByBOMFromBuffer(buffer: NodeBuffer, bytesRead: number): string {
export function detectEncodingByBOMFromBuffer(buffer: Buffer, bytesRead: number): string {
if (!buffer || bytesRead < 2) {
return null;
}
......@@ -193,7 +193,7 @@ const IGNORE_ENCODINGS = ['ascii', 'utf-8', 'utf-16', 'utf-32'];
/**
* Guesses the encoding from buffer.
*/
export function guessEncodingByBuffer(buffer: NodeBuffer): TPromise<string> {
export function guessEncodingByBuffer(buffer: Buffer): TPromise<string> {
return toWinJsPromise(import('jschardet')).then(jschardet => {
jschardet.Constants.MINIMUM_THRESHOLD = MINIMUM_THRESHOLD;
......
......@@ -365,7 +365,7 @@ export interface IWriteFileOptions {
}
let canFlush = true;
export function writeFileAndFlush(path: string, data: string | NodeBuffer | NodeJS.ReadableStream, options: IWriteFileOptions, callback: (error?: Error) => void): void {
export function writeFileAndFlush(path: string, data: string | Buffer | NodeJS.ReadableStream, options: IWriteFileOptions, callback: (error?: Error) => void): void {
options = ensureOptions(options);
if (typeof data === 'string' || Buffer.isBuffer(data)) {
......@@ -466,7 +466,7 @@ function doWriteFileStreamAndFlush(path: string, reader: NodeJS.ReadableStream,
// not in some cache.
//
// See https://github.com/nodejs/node/blob/v5.10.0/lib/fs.js#L1194
function doWriteFileAndFlush(path: string, data: string | NodeBuffer, options: IWriteFileOptions, callback: (error?: Error) => void): void {
function doWriteFileAndFlush(path: string, data: string | Buffer, options: IWriteFileOptions, callback: (error?: Error) => void): void {
if (options.encoding) {
data = encode(data, options.encoding.charset, { addBOM: options.encoding.addBOM });
}
......@@ -503,7 +503,7 @@ function doWriteFileAndFlush(path: string, data: string | NodeBuffer, options: I
});
}
export function writeFileAndFlushSync(path: string, data: string | NodeBuffer, options?: IWriteFileOptions): void {
export function writeFileAndFlushSync(path: string, data: string | Buffer, options?: IWriteFileOptions): void {
options = ensureOptions(options);
if (options.encoding) {
......
......@@ -98,7 +98,7 @@ export function readFile(path: string, encoding?: string): TPromise<Buffer | str
const writeFilePathQueue: { [path: string]: Queue<void> } = Object.create(null);
export function writeFile(path: string, data: string, options?: extfs.IWriteFileOptions): TPromise<void>;
export function writeFile(path: string, data: NodeBuffer, options?: extfs.IWriteFileOptions): TPromise<void>;
export function writeFile(path: string, data: Buffer, options?: extfs.IWriteFileOptions): TPromise<void>;
export function writeFile(path: string, data: Uint8Array, options?: extfs.IWriteFileOptions): TPromise<void>;
export function writeFile(path: string, data: NodeJS.ReadableStream, options?: extfs.IWriteFileOptions): TPromise<void>;
export function writeFile(path: string, data: any, options?: extfs.IWriteFileOptions): TPromise<void> {
......
......@@ -10,7 +10,7 @@ import * as fs from 'fs';
import { TPromise } from 'vs/base/common/winjs.base';
export interface ReadResult {
buffer: NodeBuffer;
buffer: Buffer;
bytesRead: number;
}
......@@ -24,7 +24,7 @@ export function readExactlyByFile(file: string, totalBytes: number): TPromise<Re
return error(err);
}
function end(err: Error, resultBuffer: NodeBuffer, bytesRead: number): void {
function end(err: Error, resultBuffer: Buffer, bytesRead: number): void {
fs.close(fd, closeError => {
if (closeError) {
return error(closeError);
......
......@@ -46,7 +46,7 @@ export class OutOfProcessWin32FolderWatcher {
const stdoutLineDecoder = new decoder.LineDecoder();
// Events over stdout
this.handle.stdout.on('data', (data: NodeBuffer) => {
this.handle.stdout.on('data', (data: Buffer) => {
// Collect raw events from output
const rawEvents: IRawFileChange[] = [];
......@@ -86,13 +86,13 @@ export class OutOfProcessWin32FolderWatcher {
// Errors
this.handle.on('error', (error: Error) => this.onError(error));
this.handle.stderr.on('data', (data: NodeBuffer) => this.onError(data));
this.handle.stderr.on('data', (data: Buffer) => this.onError(data));
// Exit
this.handle.on('exit', (code: number, signal: string) => this.onExit(code, signal));
}
private onError(error: Error | NodeBuffer): void {
private onError(error: Error | Buffer): void {
this.errorCallback('[FileWatcher] process error: ' + error.toString());
}
......
......@@ -177,8 +177,8 @@ export class SearchWorkerEngine {
return clb(null); // return early if canceled or limit reached
}
fs.read(fd, buffer, 0, buffer.length, null, (error: Error, bytesRead: number, buffer: NodeBuffer) => {
const decodeBuffer = (buffer: NodeBuffer, start: number, end: number): string => {
fs.read(fd, buffer, 0, buffer.length, null, (error: Error, bytesRead: number, buffer: Buffer) => {
const decodeBuffer = (buffer: Buffer, start: number, end: number): string => {
if (options.encoding === UTF8 || options.encoding === UTF8_with_bom) {
return buffer.toString(undefined, start, end); // much faster to use built in toString() when encoding is default
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册