| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('fs'); | 5 #library('fs'); |
| 6 | 6 |
| 7 #import('node.dart'); | 7 #import('node.dart'); |
| 8 #import('nodeimpl.dart'); | 8 #import('nodeimpl.dart'); |
| 9 | 9 |
| 10 | 10 |
| 11 typedef ReadStreamOpenListener(int fd); | 11 typedef ReadStreamOpenListener(int fd); |
| 12 | 12 |
| 13 class ReadStream implements ReadableStream, FsStream native "*ReadStream" { | 13 class ReadStream implements ReadableStream, FsStream native "*ReadStream" { |
| 14 // EventEmitter | 14 // EventEmitter |
| 15 void removeAllListeners(String event) native; | 15 void removeAllListeners(String event) native; |
| 16 void setMaxListeners(num n) native; | 16 void setMaxListeners(num n) native; |
| 17 _listeners(String key) | 17 _listeners(String key) |
| 18 native "return this.listeners(key);"; | 18 native "return this.listeners(key);"; |
| 19 | 19 |
| 20 // CommonStream | 20 // CommonStream |
| 21 | 21 |
| 22 // Error event | 22 // Error event |
| 23 void emitError(Error error) | 23 void emitError(Error error) |
| 24 native "this.emit('error', error);"; | 24 native "this.emit('error', error);"; |
| 25 void addListenerError(StreamErrorListener listener) | 25 void addListenerError(StreamErrorListener listener) |
| 26 native "this.addListener('error', listener);"; | 26 native "this.addListener('error', listener);"; |
| 27 void onError(StreamErrorListener listener) | 27 void onError(StreamErrorListener listener) |
| 28 native "this.on('error', listener);"; | 28 native "this.on('error', listener);"; |
| 29 void onceError(StreamErrorListener listener) | 29 void onceError(StreamErrorListener listener) |
| 30 native "this.once('error', listener);"; | 30 native "this.once('error', listener);"; |
| 31 void removeListenerError(StreamErrorListener listener) | 31 void removeListenerError(StreamErrorListener listener) |
| 32 native "this.removeListener('error', listener);"; | 32 native "this.removeListener('error', listener);"; |
| 33 List<StreamErrorListener> listenersError() | 33 List<StreamErrorListener> listenersError() |
| 34 => _listeners('error'); | 34 => _listeners('error'); |
| 35 | 35 |
| 36 // Close event | 36 // Close event |
| 37 void emitClose() | 37 void emitClose() |
| 38 native "this.emit('close');"; | 38 native "this.emit('close');"; |
| 39 void addListenerClose(StreamCloseListener listener) | 39 void addListenerClose(StreamCloseListener listener) |
| 40 native "this.addListener('close', listener);"; | 40 native "this.addListener('close', listener);"; |
| 41 void onClose(StreamCloseListener listener) | 41 void onClose(StreamCloseListener listener) |
| 42 native "this.on('close', listener);"; | 42 native "this.on('close', listener);"; |
| 43 void onceClose(StreamCloseListener listener) | 43 void onceClose(StreamCloseListener listener) |
| 44 native "this.once('close', listener);"; | 44 native "this.once('close', listener);"; |
| 45 void removeListenerClose(StreamCloseListener listener) | 45 void removeListenerClose(StreamCloseListener listener) |
| 46 native "this.removeListener('close', listener);"; | 46 native "this.removeListener('close', listener);"; |
| 47 List<StreamCloseListener> listenersClose() | 47 List<StreamCloseListener> listenersClose() |
| 48 => _listeners('close'); | 48 => _listeners('close'); |
| 49 | 49 |
| 50 // ReadableStream | 50 // ReadableStream |
| 51 | 51 |
| 52 // Data event | 52 // Data event |
| 53 void emitData(var data) | 53 void emitData(var data) |
| 54 native "this.emit('data', data);"; | 54 native "this.emit('data', data);"; |
| 55 void addListenerData(ReadableStreamDataListener listener) | 55 void addListenerData(ReadableStreamDataListener listener) |
| 56 native "this.addListener('data', listener);"; | 56 native "this.addListener('data', listener);"; |
| 57 void onData(ReadableStreamDataListener listener) | 57 void onData(ReadableStreamDataListener listener) |
| 58 native "this.on('data', listener);"; | 58 native "this.on('data', listener);"; |
| 59 void onceData(ReadableStreamDataListener listener) | 59 void onceData(ReadableStreamDataListener listener) |
| 60 native "this.once('data', listener);"; | 60 native "this.once('data', listener);"; |
| 61 void removeListenerData(ReadableStreamDataListener listener) | 61 void removeListenerData(ReadableStreamDataListener listener) |
| 62 native "this.removeListener('data', listener);"; | 62 native "this.removeListener('data', listener);"; |
| 63 List<ReadableStreamDataListener> listenerData() | 63 List<ReadableStreamDataListener> listenerData() |
| 64 => _listeners('data'); | 64 => _listeners('data'); |
| 65 | 65 |
| 66 // End event | 66 // End event |
| 67 void emitEnd() | 67 void emitEnd() |
| 68 native "this.emit('end');"; | 68 native "this.emit('end');"; |
| 69 void addListenerEnd(ReadableStreamEndListener listener) | 69 void addListenerEnd(ReadableStreamEndListener listener) |
| 70 native "this.addListener('end', listener);"; | 70 native "this.addListener('end', listener);"; |
| 71 void onEnd(ReadableStreamEndListener listener) | 71 void onEnd(ReadableStreamEndListener listener) |
| 72 native "this.on('end', listener);"; | 72 native "this.on('end', listener);"; |
| 73 void onceEnd(ReadableStreamEndListener listener) | 73 void onceEnd(ReadableStreamEndListener listener) |
| 74 native "this.once('end', listener);"; | 74 native "this.once('end', listener);"; |
| 75 void removeListenerEnd(ReadableStreamEndListener listener) | 75 void removeListenerEnd(ReadableStreamEndListener listener) |
| 76 native "this.removeListener('end', listener);"; | 76 native "this.removeListener('end', listener);"; |
| 77 List<ReadableStreamEndListener> listenersEnd() | 77 List<ReadableStreamEndListener> listenersEnd() |
| 78 => _listeners('end'); | 78 => _listeners('end'); |
| 79 | 79 |
| 80 // FsStream | 80 // FsStream |
| 81 | 81 |
| 82 // Open event | 82 // Open event |
| 83 void emitOpen(int fd) | 83 void emitOpen(int fd) |
| 84 native "this.emit('open', fd);"; | 84 native "this.emit('open', fd);"; |
| 85 void addListenerOpen(FsStreamOpenListener listener) | 85 void addListenerOpen(FsStreamOpenListener listener) |
| 86 native "this.addListener('open', listener);"; | 86 native "this.addListener('open', listener);"; |
| 87 void onOpen(FsStreamOpenListener listener) | 87 void onOpen(FsStreamOpenListener listener) |
| 88 native "this.on('open', listener);"; | 88 native "this.on('open', listener);"; |
| 89 void onceOpen(FsStreamOpenListener listener) | 89 void onceOpen(FsStreamOpenListener listener) |
| 90 native "this.once('open', listener);"; | 90 native "this.once('open', listener);"; |
| 91 void removeListenerOpen(FsStreamOpenListener listener) | 91 void removeListenerOpen(FsStreamOpenListener listener) |
| 92 native "this.removeListener('open', listener);"; | 92 native "this.removeListener('open', listener);"; |
| 93 List<FsStreamOpenListener> listenersOpen() | 93 List<FsStreamOpenListener> listenersOpen() |
| 94 => _listeners('open'); | 94 => _listeners('open'); |
| 95 | 95 |
| 96 bool readable; | 96 bool readable; |
| 97 void setEncoding(String encoding) native; | 97 void setEncoding(String encoding) native; |
| 98 void pause() native; | 98 void pause() native; |
| 99 void resume() native; | 99 void resume() native; |
| 100 void destroy() native; | 100 void destroy() native; |
| 101 void destroySoon() native; | 101 void destroySoon() native; |
| 102 WritableStream pipe(WritableStream destination, [Map options]) native; | 102 WritableStream pipe(WritableStream destination, [Map options]) native; |
| 103 } | 103 } |
| 104 | 104 |
| 105 class WriteStream implements WritableStream, FsStream native "*WriteStream" { | 105 class WriteStream implements WritableStream, FsStream native "*WriteStream" { |
| 106 // EventEmitter | 106 // EventEmitter |
| 107 void removeAllListeners(String event) native; | 107 void removeAllListeners(String event) native; |
| 108 void setMaxListeners(num n) native; | 108 void setMaxListeners(num n) native; |
| 109 _listeners(String key) | 109 _listeners(String key) |
| 110 native "return this.listeners(key);"; | 110 native "return this.listeners(key);"; |
| 111 | 111 |
| 112 // CommonStream | 112 // CommonStream |
| 113 | 113 |
| 114 // Error event | 114 // Error event |
| 115 void emitError(Error error) | 115 void emitError(Error error) |
| 116 native "this.emit('error', error);"; | 116 native "this.emit('error', error);"; |
| 117 void addListenerError(StreamErrorListener listener) | 117 void addListenerError(StreamErrorListener listener) |
| 118 native "this.addListener('error', listener);"; | 118 native "this.addListener('error', listener);"; |
| 119 void onError(StreamErrorListener listener) | 119 void onError(StreamErrorListener listener) |
| 120 native "this.on('error', listener);"; | 120 native "this.on('error', listener);"; |
| 121 void onceError(StreamErrorListener listener) | 121 void onceError(StreamErrorListener listener) |
| 122 native "this.once('error', listener);"; | 122 native "this.once('error', listener);"; |
| 123 void removeListenerError(StreamErrorListener listener) | 123 void removeListenerError(StreamErrorListener listener) |
| 124 native "this.removeListener('error', listener);"; | 124 native "this.removeListener('error', listener);"; |
| 125 List<StreamErrorListener> listenersError() | 125 List<StreamErrorListener> listenersError() |
| 126 => _listeners('error'); | 126 => _listeners('error'); |
| 127 | 127 |
| 128 // Close event | 128 // Close event |
| 129 void emitClose() | 129 void emitClose() |
| 130 native "this.emit('close');"; | 130 native "this.emit('close');"; |
| 131 void addListenerClose(StreamCloseListener listener) | 131 void addListenerClose(StreamCloseListener listener) |
| 132 native "this.addListener('close', listener);"; | 132 native "this.addListener('close', listener);"; |
| 133 void onClose(StreamCloseListener listener) | 133 void onClose(StreamCloseListener listener) |
| 134 native "this.on('close', listener);"; | 134 native "this.on('close', listener);"; |
| 135 void onceClose(StreamCloseListener listener) | 135 void onceClose(StreamCloseListener listener) |
| 136 native "this.once('close', listener);"; | 136 native "this.once('close', listener);"; |
| 137 void removeListenerClose(StreamCloseListener listener) | 137 void removeListenerClose(StreamCloseListener listener) |
| 138 native "this.removeListener('close', listener);"; | 138 native "this.removeListener('close', listener);"; |
| 139 List<StreamCloseListener> listenersClose() | 139 List<StreamCloseListener> listenersClose() |
| 140 => _listeners('close'); | 140 => _listeners('close'); |
| 141 | 141 |
| 142 // WritableStream | 142 // WritableStream |
| 143 | 143 |
| 144 // Drain event | 144 // Drain event |
| 145 void emitDrain() | 145 void emitDrain() |
| 146 native "this.emit('drain');"; | 146 native "this.emit('drain');"; |
| 147 void addListenerDrain(WritableStreamDrainListener listener) | 147 void addListenerDrain(WritableStreamDrainListener listener) |
| 148 native "this.addListener('drain', listener);"; | 148 native "this.addListener('drain', listener);"; |
| 149 void onDrain(WritableStreamDrainListener listener) | 149 void onDrain(WritableStreamDrainListener listener) |
| 150 native "this.on('drain', listener);"; | 150 native "this.on('drain', listener);"; |
| 151 void onceDrain(WritableStreamDrainListener listener) | 151 void onceDrain(WritableStreamDrainListener listener) |
| 152 native "this.once('drain', listener);"; | 152 native "this.once('drain', listener);"; |
| 153 void removeListenerDrain(WritableStreamDrainListener listener) | 153 void removeListenerDrain(WritableStreamDrainListener listener) |
| 154 native "this.removeListener('drain', listener);"; | 154 native "this.removeListener('drain', listener);"; |
| 155 List<WritableStreamDrainListener> listenersDrain() | 155 List<WritableStreamDrainListener> listenersDrain() |
| 156 => _listeners('drain'); | 156 => _listeners('drain'); |
| 157 | 157 |
| 158 // Pipe event | 158 // Pipe event |
| 159 void emitPipe(ReadableStream src) | 159 void emitPipe(ReadableStream src) |
| 160 native "this.emit('pipe', src);"; | 160 native "this.emit('pipe', src);"; |
| 161 void addListenerPipe(WritableStreamPipeListener listener) | 161 void addListenerPipe(WritableStreamPipeListener listener) |
| 162 native "this.addListener('pipe', listener);"; | 162 native "this.addListener('pipe', listener);"; |
| 163 void onPipe(WritableStreamPipeListener listener) | 163 void onPipe(WritableStreamPipeListener listener) |
| 164 native "this.on('pipe', listener);"; | 164 native "this.on('pipe', listener);"; |
| 165 void oncePipe(WritableStreamPipeListener listener) | 165 void oncePipe(WritableStreamPipeListener listener) |
| 166 native "this.once('pipe', listener);"; | 166 native "this.once('pipe', listener);"; |
| 167 void removeListenerPipe(WritableStreamPipeListener listener) | 167 void removeListenerPipe(WritableStreamPipeListener listener) |
| 168 native "this.removeListener('pipe', listener);"; | 168 native "this.removeListener('pipe', listener);"; |
| 169 List<WritableStreamPipeListener> listenersPipe() | 169 List<WritableStreamPipeListener> listenersPipe() |
| 170 => _listeners('pipe'); | 170 => _listeners('pipe'); |
| 171 | 171 |
| 172 // FsStream | 172 // FsStream |
| 173 | 173 |
| 174 // Open event | 174 // Open event |
| 175 void emitOpen(int fd) | 175 void emitOpen(int fd) |
| 176 native "this.emit('open', fd);"; | 176 native "this.emit('open', fd);"; |
| 177 void addListenerOpen(FsStreamOpenListener listener) | 177 void addListenerOpen(FsStreamOpenListener listener) |
| 178 native "this.addListener('open', listener);"; | 178 native "this.addListener('open', listener);"; |
| 179 void onOpen(FsStreamOpenListener listener) | 179 void onOpen(FsStreamOpenListener listener) |
| 180 native "this.on('open', listener);"; | 180 native "this.on('open', listener);"; |
| 181 void onceOpen(FsStreamOpenListener listener) | 181 void onceOpen(FsStreamOpenListener listener) |
| 182 native "this.once('open', listener);"; | 182 native "this.once('open', listener);"; |
| 183 void removeListenerOpen(FsStreamOpenListener listener) | 183 void removeListenerOpen(FsStreamOpenListener listener) |
| 184 native "this.removeListener('open', listener);"; | 184 native "this.removeListener('open', listener);"; |
| 185 List<FsStreamOpenListener> listenersOpen() | 185 List<FsStreamOpenListener> listenersOpen() |
| 186 => _listeners('open'); | 186 => _listeners('open'); |
| 187 | 187 |
| 188 bool writable; | 188 bool writable; |
| 189 bool write(String string, [String encoding='utf8', int fd]) native; | 189 bool write(String string, [String encoding='utf8', int fd]) native; |
| 190 bool writeBuffer(Buffer buffer) native; | 190 bool writeBuffer(Buffer buffer) native; |
| 191 void end([String string, String encoding]) native; | 191 void end([String string, String encoding]) native; |
| 192 void endBuffer(Buffer buffer) native "this.end(buffer);"; | 192 void endBuffer(Buffer buffer) native "this.end(buffer);"; |
| 193 void destroy() native; | 193 void destroy() native; |
| 194 void destroySoon() native; | 194 void destroySoon() native; |
| 195 | 195 |
| 196 List<int> getWindowSize() native; | 196 List<int> getWindowSize() native; |
| 197 | 197 |
| 198 int bytesWritten; | 198 int bytesWritten; |
| 199 } | 199 } |
| 200 | 200 |
| 201 typedef void FsRenameCallback(Error err); | 201 typedef void FsRenameCallback(Error err); |
| 202 typedef void FsTruncateCallback(Error err); | 202 typedef void FsTruncateCallback(Error err); |
| 203 typedef void FsChownCallback(Error err); | 203 typedef void FsChownCallback(Error err); |
| 204 typedef void FsFchownCallback(Error err); | 204 typedef void FsFchownCallback(Error err); |
| 205 typedef void FsLchownCallback(Error err); | 205 typedef void FsLchownCallback(Error err); |
| 206 typedef void FsChmodCallback(Error err); | 206 typedef void FsChmodCallback(Error err); |
| 207 typedef void FsFchmodCallback(Error err); | 207 typedef void FsFchmodCallback(Error err); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 226 typedef void FsReadCallback(Error err, int bytesRead, Buffer buffer); | 226 typedef void FsReadCallback(Error err, int bytesRead, Buffer buffer); |
| 227 typedef void FsReadFileCallback(Error err, String data); | 227 typedef void FsReadFileCallback(Error err, String data); |
| 228 typedef void FsReadFileBufferCallback(Error err, Buffer data); | 228 typedef void FsReadFileBufferCallback(Error err, Buffer data); |
| 229 typedef void FsWriteFileCallback(Error err); | 229 typedef void FsWriteFileCallback(Error err); |
| 230 typedef void FsWriteFileBufferCallback(Error err); | 230 typedef void FsWriteFileBufferCallback(Error err); |
| 231 typedef void FsWatchFileListener(Stats curr, Stats prev); | 231 typedef void FsWatchFileListener(Stats curr, Stats prev); |
| 232 | 232 |
| 233 class Fs { | 233 class Fs { |
| 234 var _fs; | 234 var _fs; |
| 235 Fs.from(this._fs); | 235 Fs.from(this._fs); |
| 236 | 236 |
| 237 void rename(String path1, String path2, [FsRenameCallback callback]) | 237 void rename(String path1, String path2, [FsRenameCallback callback]) |
| 238 native "this._fs.rename(path1, path2, callback);"; | 238 native "this._fs.rename(path1, path2, callback);"; |
| 239 void renameSync(String path1, String path2) | 239 void renameSync(String path1, String path2) |
| 240 native "this._fs.renameSync(path1, path2);"; | 240 native "this._fs.renameSync(path1, path2);"; |
| 241 | 241 |
| 242 void truncate(int fd, int len, [FsTruncateCallback callback]) | 242 void truncate(int fd, int len, [FsTruncateCallback callback]) |
| 243 native "this._fs.truncate(fd, len, callback);"; | 243 native "this._fs.truncate(fd, len, callback);"; |
| 244 void truncateSync(int fd, int len) | 244 void truncateSync(int fd, int len) |
| 245 native "this._fs.truncateSync(fd, len);"; | 245 native "this._fs.truncateSync(fd, len);"; |
| 246 | 246 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 FSWatcher watch(String filename, FSWatcherChangeListener listener, [Map | 404 FSWatcher watch(String filename, FSWatcherChangeListener listener, [Map |
| 405 options]) | 405 options]) |
| 406 native "return this._fs.watch(filename, options, listener);"; | 406 native "return this._fs.watch(filename, options, listener);"; |
| 407 | 407 |
| 408 ReadStream createReadStream(String path, [Map options]) | 408 ReadStream createReadStream(String path, [Map options]) |
| 409 native "return this._fs.createReadStream(path, options);"; | 409 native "return this._fs.createReadStream(path, options);"; |
| 410 WriteStream createWriteStream(String path, [Map options]) | 410 WriteStream createWriteStream(String path, [Map options]) |
| 411 native "return this._fs.createWriteStream(path, options);"; | 411 native "return this._fs.createWriteStream(path, options);"; |
| 412 } | 412 } |
| 413 | 413 |
| 414 Fs get fs() => require('fs'); | 414 Fs get fs() => new Fs.from(require('fs')); |
| 415 | 415 |
| 416 class Stats native "fs.Stats" { | 416 class Stats native "fs.Stats" { |
| 417 bool isFile() native; | 417 bool isFile() native; |
| 418 bool isDirectory() native; | 418 bool isDirectory() native; |
| 419 bool isBlockDevice() native; | 419 bool isBlockDevice() native; |
| 420 bool isCharacterDevice() native; | 420 bool isCharacterDevice() native; |
| 421 bool isSymbolicLink() native; | 421 bool isSymbolicLink() native; |
| 422 bool isFIFO() native; | 422 bool isFIFO() native; |
| 423 bool isSocket() native; | 423 bool isSocket() native; |
| 424 | 424 |
| 425 int dev; | 425 int dev; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 455 void addListenerError(FSWatcherErrorListener listener) | 455 void addListenerError(FSWatcherErrorListener listener) |
| 456 native "this.addListener('error', listener);"; | 456 native "this.addListener('error', listener);"; |
| 457 void onError(FSWatcherErrorListener listener) | 457 void onError(FSWatcherErrorListener listener) |
| 458 native "this.on('error', listener);"; | 458 native "this.on('error', listener);"; |
| 459 void onceError(FSWatcherErrorListener listener) | 459 void onceError(FSWatcherErrorListener listener) |
| 460 native "this.once('error', listener);"; | 460 native "this.once('error', listener);"; |
| 461 void removeListenerError(FSWatcherErrorListener listener) | 461 void removeListenerError(FSWatcherErrorListener listener) |
| 462 native "this.removeListener('error', listener);"; | 462 native "this.removeListener('error', listener);"; |
| 463 List<FSWatcherErrorListener> listenersError() | 463 List<FSWatcherErrorListener> listenersError() |
| 464 => _listeners('error'); | 464 => _listeners('error'); |
| 465 | 465 |
| 466 // Change event | 466 // Change event |
| 467 void emitChange(String event, String filename) | 467 void emitChange(String event, String filename) |
| 468 native "this.emit('change', event, filename);"; | 468 native "this.emit('change', event, filename);"; |
| 469 void addListenerChange(FSWatcherChangeListener listener) | 469 void addListenerChange(FSWatcherChangeListener listener) |
| 470 native "this.addListener('change', listener);"; | 470 native "this.addListener('change', listener);"; |
| 471 void onChange(FSWatcherChangeListener listener) | 471 void onChange(FSWatcherChangeListener listener) |
| 472 native "this.on('change', listener);"; | 472 native "this.on('change', listener);"; |
| 473 void onceChange(FSWatcherChangeListener listener) | 473 void onceChange(FSWatcherChangeListener listener) |
| 474 native "this.once('change', listener);"; | 474 native "this.once('change', listener);"; |
| 475 void removeListenerChange(FSWatcherChangeListener listener) | 475 void removeListenerChange(FSWatcherChangeListener listener) |
| 476 native "this.removeListener('change', listener);"; | 476 native "this.removeListener('change', listener);"; |
| 477 List<FSWatcherChangeListener> listenersChange() | 477 List<FSWatcherChangeListener> listenersChange() |
| 478 => _listeners('change'); | 478 => _listeners('change'); |
| 479 } | 479 } |
| OLD | NEW |