diff --git a/node/node-tests.ts b/node/node-tests.ts index 49b43302b..397a9dfa4 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -21,7 +21,9 @@ assert.doesNotThrow(() => { if (false) { throw "a hammer at your face"; } }, undefined, "What the...*crunch*"); - +//////////////////////////////////////////////////// +/// File system tests : http://nodejs.org/api/fs.html +//////////////////////////////////////////////////// fs.writeFile("thebible.txt", "Do unto others as you would have them do unto you.", assert.ifError); @@ -33,6 +35,18 @@ fs.writeFile("Harry Potter", }, assert.ifError); +var content: string, + buffer: NodeBuffer; + +content = fs.readFileSync('testfile', 'utf8'); +content = fs.readFileSync('testfile', {encoding : 'utf8'}); +buffer = fs.readFileSync('testfile'); +buffer = fs.readFileSync('testfile', {flag : 'r'}); +fs.readFile('testfile', 'utf8', (err, data) => content = data); +fs.readFile('testfile', {encoding : 'utf8'}, (err, data) => content = data); +fs.readFile('testfile', (err, data) => buffer = data); +fs.readFile('testfile', {flag : 'r'}, (err, data) => buffer = data); + class Networker extends events.EventEmitter { constructor() { super(); @@ -65,4 +79,4 @@ function stream_readable_pipe_test() { var z = zlib.createGzip(); var w = fs.createWriteStream('file.txt.gz'); r.pipe(z).pipe(w); -} \ No newline at end of file +} diff --git a/node/node.d.ts b/node/node.d.ts index fe7fbd324..a0473ad8b 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -848,10 +848,13 @@ declare module "fs" { export function writeSync(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number): number; export function read(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: ErrnoException, bytesRead: number, buffer: NodeBuffer) => void): void; export function readSync(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number): number; - export function readFile(filename: string, options: { encoding?: string; flag?: string; }, callback: (err: ErrnoException, data: any) => void): void; + export function readFile(filename: string, encoding: string, callback: (err: ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { flag?: string; }, callback: (err: ErrnoException, data: NodeBuffer) => void): void; export function readFile(filename: string, callback: (err: ErrnoException, data: NodeBuffer) => void ): void; - export function readFileSync(filename: string, options?: { flag?: string; }): NodeBuffer; + export function readFileSync(filename: string, encoding: string): string; export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; + export function readFileSync(filename: string, options?: { flag?: string; }): NodeBuffer; export function writeFile(filename: string, data: any, callback?: (err: ErrnoException) => void): void; export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: ErrnoException) => void): void; export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: ErrnoException) => void): void;