OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #library('fs'); |
| 6 |
| 7 #import('node.dart'); |
| 8 #import('nodeimpl.dart'); |
| 9 |
| 10 |
| 11 typedef ReadStreamOpenListener(int fd); |
| 12 |
| 13 class ReadStream implements ReadableStream, FsStream native "*ReadStream" { |
| 14 // EventEmitter |
| 15 void removeAllListeners(String event) native; |
| 16 void setMaxListeners(num n) native; |
| 17 var _listeners(String key) |
| 18 native "return this.listeners(key);"; |
| 19 |
| 20 // CommonStream |
| 21 |
| 22 // Error event |
| 23 void emitError(Error error) |
| 24 native "this.emit('error', error);"; |
| 25 void addListenerError(StreamErrorListener listener) |
| 26 native "this.addListener('error', listener);"; |
| 27 void onError(StreamErrorListener listener) |
| 28 native "this.on('error', listener);"; |
| 29 void onceError(StreamErrorListener listener) |
| 30 native "this.once('error', listener);"; |
| 31 void removeListenerError(StreamErrorListener listener) |
| 32 native "this.removeListener('error', listener);"; |
| 33 List<StreamErrorListener> listenersError() |
| 34 => new _NativeListPrimitiveElement<StreamErrorListener>(_listeners( |
| 35 'error')); |
| 36 |
| 37 // Close event |
| 38 void emitClose() |
| 39 native "this.emit('close');"; |
| 40 void addListenerClose(StreamCloseListener listener) |
| 41 native "this.addListener('close', listener);"; |
| 42 void onClose(StreamCloseListener listener) |
| 43 native "this.on('close', listener);"; |
| 44 void onceClose(StreamCloseListener listener) |
| 45 native "this.once('close', listener);"; |
| 46 void removeListenerClose(StreamCloseListener listener) |
| 47 native "this.removeListener('close', listener);"; |
| 48 List<StreamCloseListener> listenersClose() |
| 49 => new _NativeListPrimitiveElement<StreamCloseListener>(_listeners( |
| 50 'close')); |
| 51 |
| 52 // ReadableStream |
| 53 |
| 54 // Data event |
| 55 void emitData(var data) |
| 56 native "this.emit('data', data);"; |
| 57 void addListenerData(ReadableStreamDataListener listener) |
| 58 native "this.addListener('data', listener);"; |
| 59 void onData(ReadableStreamDataListener listener) |
| 60 native "this.on('data', listener);"; |
| 61 void onceData(ReadableStreamDataListener listener) |
| 62 native "this.once('data', listener);"; |
| 63 void removeListenerData(ReadableStreamDataListener listener) |
| 64 native "this.removeListener('data', listener);"; |
| 65 List<ReadableStreamDataListener> listenerData() |
| 66 => new _NativeListPrimitiveElement<ReadableStreamDataListener>(_listeners( |
| 67 'data')); |
| 68 |
| 69 // End event |
| 70 void emitEnd() |
| 71 native "this.emit('end');"; |
| 72 void addListenerEnd(ReadableStreamEndListener listener) |
| 73 native "this.addListener('end', listener);"; |
| 74 void onEnd(ReadableStreamEndListener listener) |
| 75 native "this.on('end', listener);"; |
| 76 void onceEnd(ReadableStreamEndListener listener) |
| 77 native "this.once('end', listener);"; |
| 78 void removeListenerEnd(ReadableStreamEndListener listener) |
| 79 native "this.removeListener('end', listener);"; |
| 80 List<ReadableStreamEndListener> listenersEnd() |
| 81 => new _NativeListPrimitiveElement<ReadableStreamEndListener>(_listeners( |
| 82 'end')); |
| 83 |
| 84 // FsStream |
| 85 |
| 86 // Open event |
| 87 void emitOpen(int fd) |
| 88 native "this.emit('open', fd);"; |
| 89 void addListenerOpen(FsStreamOpenListener listener) |
| 90 native "this.addListener('open', listener);"; |
| 91 void onOpen(FsStreamOpenListener listener) |
| 92 native "this.on('open', listener);"; |
| 93 void onceOpen(FsStreamOpenListener listener) |
| 94 native "this.once('open', listener);"; |
| 95 void removeListenerOpen(FsStreamOpenListener listener) |
| 96 native "this.removeListener('open', listener);"; |
| 97 List<FsStreamOpenListener> listenersOpen() |
| 98 => new _NativeListPrimitiveElement<FsStreamOpenListener>(_listeners( |
| 99 'open')); |
| 100 |
| 101 bool readable; |
| 102 void setEncoding(String encoding) native; |
| 103 void pause() native; |
| 104 void resume() native; |
| 105 void destroy() native; |
| 106 void destroySoon() native; |
| 107 WritableStream pipe(WritableStream destination, [Map options]) native; |
| 108 } |
| 109 |
| 110 class WriteStream implements WritableStream, FsStream native "*WriteStream" { |
| 111 // EventEmitter |
| 112 void removeAllListeners(String event) |
| 113 native "this._writeStream.removeAllListeners(event);"; |
| 114 void setMaxListeners(num n) native; |
| 115 var _listeners(String key) |
| 116 native "return this.listeners(key);"; |
| 117 |
| 118 // CommonStream |
| 119 |
| 120 // Error event |
| 121 void emitError(Error error) |
| 122 native "this.emit('error', error);"; |
| 123 void addListenerError(StreamErrorListener listener) |
| 124 native "this.addListener('error', listener);"; |
| 125 void onError(StreamErrorListener listener) |
| 126 native "this.on('error', listener);"; |
| 127 void onceError(StreamErrorListener listener) |
| 128 native "this.once('error', listener);"; |
| 129 void removeListenerError(StreamErrorListener listener) |
| 130 native "this.removeListener('error', listener);"; |
| 131 List<StreamErrorListener> listenersError() |
| 132 => new _NativeListPrimitiveElement<StreamErrorListener>(_listeners( |
| 133 'error')); |
| 134 |
| 135 // Close event |
| 136 void emitClose() |
| 137 native "this.emit('close');"; |
| 138 void addListenerClose(StreamCloseListener listener) |
| 139 native "this.addListener('close', listener);"; |
| 140 void onClose(StreamCloseListener listener) |
| 141 native "this.on('close', listener);"; |
| 142 void onceClose(StreamCloseListener listener) |
| 143 native "this.once('close', listener);"; |
| 144 void removeListenerClose(StreamCloseListener listener) |
| 145 native "this.removeListener('close', listener);"; |
| 146 List<StreamCloseListener> listenersClose() |
| 147 => new _NativeListPrimitiveElement<StreamCloseListener>(_listeners( |
| 148 'close')); |
| 149 |
| 150 // WritableStream |
| 151 |
| 152 // Drain event |
| 153 void emitDrain() |
| 154 native "this.emit('drain');"; |
| 155 void addListenerDrain(WritableStreamDrainListener listener) |
| 156 native "this.addListener('drain', listener);"; |
| 157 void onDrain(WritableStreamDrainListener listener) |
| 158 native "this.on('drain', listener);"; |
| 159 void onceDrain(WritableStreamDrainListener listener) |
| 160 native "this.once('drain', listener);"; |
| 161 void removeListenerDrain(WritableStreamDrainListener listener) |
| 162 native "this.removeListener('drain', listener);"; |
| 163 List<WritableStreamDrainListener> listenersDrain() |
| 164 => new _NativeListPrimitiveElement<WritableStreamDrainListener>(_listeners( |
| 165 'drain')); |
| 166 |
| 167 // Pipe event |
| 168 void emitPipe(ReadableStream src) |
| 169 native "this.emit('pipe', src);"; |
| 170 void addListenerPipe(WritableStreamPipeListener listener) |
| 171 native "this.addListener('pipe', listener);"; |
| 172 void onPipe(WritableStreamPipeListener listener) |
| 173 native "this.on('pipe', listener);"; |
| 174 void oncePipe(WritableStreamPipeListener listener) |
| 175 native "this.once('pipe', listener);"; |
| 176 void removeListenerPipe(WritableStreamPipeListener listener) |
| 177 native "this.removeListener('pipe', listener);"; |
| 178 List<WritableStreamPipeListener> listenersPipe() |
| 179 => new _NativeListPrimitiveElement<WritableStreamPipeListener>(_listeners( |
| 180 'pipe')); |
| 181 |
| 182 // FsStream |
| 183 |
| 184 // Open event |
| 185 void emitOpen(int fd) |
| 186 native "this.emit('open', fd);"; |
| 187 void addListenerOpen(FsStreamOpenListener listener) |
| 188 native "this.addListener('open', listener);"; |
| 189 void onOpen(FsStreamOpenListener listener) |
| 190 native "this.on('open', listener);"; |
| 191 void onceOpen(FsStreamOpenListener listener) |
| 192 native "this.once('open', listener);"; |
| 193 void removeListenerOpen(FsStreamOpenListener listener) |
| 194 native "this.removeListener('open', listener);"; |
| 195 List<FsStreamOpenListener> listenersOpen() |
| 196 => new _NativeListPrimitiveElement<FsStreamOpenListener>(_listeners( |
| 197 'open')); |
| 198 |
| 199 bool writable; |
| 200 bool write(String string, [String encoding='utf8', int fd]) native; |
| 201 bool writeBuffer(Buffer buffer) native; |
| 202 void end([String string, String encoding]) native; |
| 203 void endBuffer(Buffer buffer) native "this.end(buffer);"; |
| 204 void destroy() native; |
| 205 void destroySoon() native; |
| 206 |
| 207 List<int> getWindowSize() => new _NativeListPrimitiveElement<int> |
| 208 (_getWindowSize()); |
| 209 var _getWindowSize() native "return this.getWindowSize();"; |
| 210 |
| 211 int bytesWritten; |
| 212 } |
| 213 |
| 214 typedef void FsRenameCallback(Error err); |
| 215 typedef void FsTruncateCallback(Error err); |
| 216 typedef void FsChownCallback(Error err); |
| 217 typedef void FsFchownCallback(Error err); |
| 218 typedef void FsLchownCallback(Error err); |
| 219 typedef void FsChmodCallback(Error err); |
| 220 typedef void FsFchmodCallback(Error err); |
| 221 typedef void FsLchmodCallback(Error err); |
| 222 typedef void FsStatCallback(Error err, Stats stats); |
| 223 typedef void FsLstatCallback(Error err, Stats stats); |
| 224 typedef void FsFstatCallback(Error err, Stats stats); |
| 225 typedef void FsLinkCallback(Error err); |
| 226 typedef void FsSymlinkCallback(Error err); |
| 227 typedef void FsReadlinkCallback(Error err, String linkString); |
| 228 typedef void FsRealpathCallback(Error err, String resolvedPath); |
| 229 typedef void FsUnlinkCallback(Error err); |
| 230 typedef void FsRmdirCallback(Error err); |
| 231 typedef void FsMkdirCallback(Error err); |
| 232 typedef void FsReaddirCallback(Error err, List<String> files); |
| 233 typedef void FsCloseCallback(Error err); |
| 234 typedef void FsOpenCallback(Error err); |
| 235 typedef void FsUtimesCallback(Error err); |
| 236 typedef void FsFutimesCallback(Error err); |
| 237 typedef void FsFsyncCallback(Error err); |
| 238 typedef void FsWriteCallback(Error err, int written, Buffer buffer); |
| 239 typedef void FsReadCallback(Error err, int bytesRead, Buffer buffer); |
| 240 typedef void FsReadFileCallback(Error err, String data); |
| 241 typedef void FsReadFileBufferCallback(Error err, Buffer data); |
| 242 typedef void FsWriteFileCallback(Error err); |
| 243 typedef void FsWriteFileBufferCallback(Error err); |
| 244 typedef void FsWatchFileListener(Stats curr, Stats prev); |
| 245 |
| 246 class Fs { |
| 247 var _fs; |
| 248 Fs.from(this._fs); |
| 249 |
| 250 void rename(String path1, String path2, [FsRenameCallback callback]) |
| 251 native "this._fs.rename(path1, path2, callback);"; |
| 252 void renameSync(String path1, String path2) |
| 253 native "this._fs.renameSync(path1, path2);"; |
| 254 |
| 255 void truncate(int fd, int len, [FsTruncateCallback callback]) |
| 256 native "this._fs.truncate(fd, len, callback);"; |
| 257 void truncateSync(int fd, int len) |
| 258 native "this._fs.truncateSync(fd, len);"; |
| 259 |
| 260 void chown(String path, int uid, int gid, [FsChownCallback callback]) |
| 261 native "this._fs.chown(path, uid, gid, callback);"; |
| 262 void chownSync(String path, int uid, int gid) |
| 263 native "this._fs.chownSync(path, uid, gid);"; |
| 264 |
| 265 void fchown(int fd, int uid, int gid, [FsFchownCallback callback]) |
| 266 native "this._fs.fchown(fd, uid, gid, callback);"; |
| 267 void fchownSync(int fd, int uid, int gid) |
| 268 native "this._fs.fchownSync(fd, uid, gid);"; |
| 269 |
| 270 void lchown(String path, int uid, int gid, [FsFchownCallback callback]) |
| 271 native "this._fs.lchown(path, uid, gid, callback);"; |
| 272 void lchownSync(String path, int uid, int gid) |
| 273 native "this._fs.lchownSync(path, uid, gid);"; |
| 274 |
| 275 void chmod(String path, int mode, [FsChmodCallback callback]) |
| 276 native "this._fs.chmod(path, mode, callback);"; |
| 277 void chmodSync(String path, int mode) |
| 278 native "this._fs.chmodSync(path, mode);"; |
| 279 |
| 280 void fchmod(int fd, int mode, [FsFchmodCallback callback]) |
| 281 native "this._fs.fchmod(fd, mode, callback);"; |
| 282 void fchmodSync(int fd, int mode) |
| 283 native "this._fs.fchmodSync(fd, mode);"; |
| 284 |
| 285 void lchmod(String path, int mode, [FsLchmodCallback callback]) |
| 286 native "this._fs.lchmod(path, mode, callback);"; |
| 287 void lchmodSync(String path, int mode) |
| 288 native "this._fs.lchmodSync(path, mode);"; |
| 289 |
| 290 void stat(String path, [FsStatCallback callback]) |
| 291 native "this._fs.stat(path, callback);"; |
| 292 void lstat(String path, [FsLstatCallback callback]) |
| 293 native "this._fs.lstat(path, callback);"; |
| 294 void fstat(int fd, [FsFstatCallback callback]) |
| 295 native "this._fs.fstat(fd, callback);"; |
| 296 |
| 297 Stats statSync(String path) |
| 298 native "return this._fs.statSync(path);"; |
| 299 Stats lstatSync(String path) |
| 300 native "return this._fs.lstatSync(path);"; |
| 301 Stats fstatSync(int fd) |
| 302 native "return this._fs.fstatSync(fd);"; |
| 303 |
| 304 void link(String srcpath, String dstpath, [FsLinkCallback callback]) |
| 305 native "this._fs.link(srcpath, dstpath, callback);"; |
| 306 void linkSync(String srcpath, String dstpath) |
| 307 native "this._fs.linkSync(srcpath, dstpath);"; |
| 308 |
| 309 void symlink(String linkdata, String path, [FsSymlinkCallback callback]) |
| 310 native "this._fs.symlink(linkdata, path, callback);"; |
| 311 void symlinkSync(String linkdata, String path) |
| 312 native "this._fs.symlinkSync(linkdata, path);"; |
| 313 |
| 314 void readlink(String path, [FsReadlinkCallback callback]) |
| 315 native "this._fs.readlink(path, callback);"; |
| 316 String readlinkSync(String path) |
| 317 native "return this._fs.readlinkSync(path);"; |
| 318 |
| 319 void realpath(String path, [FsRealpathCallback callback]) |
| 320 native "this._fs.realpath(path, callback);"; |
| 321 String realpathSync(String path) |
| 322 native "return this._fs.realpathSync(path);"; |
| 323 |
| 324 void unlink(String path, [FsUnlinkCallback callback]) |
| 325 native "this._fs.unlink(path, callback);"; |
| 326 void unlinkSync(String path) |
| 327 native "this._fs.unlinkSync(path);"; |
| 328 |
| 329 void rmdir(String path, [FsRmdirCallback callback]) |
| 330 native "this._fs.rmdir(path, callback);"; |
| 331 void rmdirSync(String path) |
| 332 native "this._fs.rmdirSync(path);"; |
| 333 |
| 334 void mkdir(String path, [int mode = 511 /* 0777 octal */, FsMkdirCallback |
| 335 callback]) |
| 336 native "this._fs.mkdir(path, mode, callback);"; |
| 337 void mkdirSync(String path, [int mode = 511 /* 0777 octal */]) |
| 338 native "this._fs.mkdirSync(path, mode);"; |
| 339 |
| 340 void readdir(String path, [FsReaddirCallback callback]) |
| 341 native "this._fs.readdir(path, callback);"; |
| 342 List<String> readdirSync(String path) |
| 343 => new _NativeListPrimitiveElement<String>(_readdirSync(path)); |
| 344 var _readdirSync(String path) |
| 345 native "return this._fs.readdirSync(path);"; |
| 346 |
| 347 void close(int fd, [FsCloseCallback callback]) |
| 348 native "this._fs.close(fd, callback);"; |
| 349 void closeSync(int fd) |
| 350 native "this._fs.closeSync(fd);"; |
| 351 |
| 352 void open(String path, String flags, [int mode = 438 /* 0666 octal */, |
| 353 FsOpenCallback callback]) |
| 354 native "this._fs.open(path, flags, mode, callback);"; |
| 355 void openSync(String path, String flags, [int mode = 438 /* 0666 octal */]) |
| 356 native "this._fs.openSync(path, flags, mode);"; |
| 357 |
| 358 void utimes(String path, int atime, int mtime, [FsUtimesCallback callback]) |
| 359 native "this._fs.utimes(path, atime, mtime, callback);"; |
| 360 void utimesSync(String path, int atime, int mtime) |
| 361 native "this._fs.utimesSync(path, atime, mtime);"; |
| 362 |
| 363 void futimes(int fd, int atime, int mtime, [FsUtimesCallback callback]) |
| 364 native "this._fs.futimes(fd, atime, mtime, callback);"; |
| 365 void futimesSync(int fd, int atime, int mtime) |
| 366 native "this._fs.futimesSync(fd, atime, mtime);"; |
| 367 |
| 368 void fsync(int fd, [FsFsyncCallback callback]) |
| 369 native "this._fs.fsync(fd, callback);"; |
| 370 void fsyncSync(int fd) |
| 371 native "this._fs.fsyncSync(fd);"; |
| 372 |
| 373 void write(int fd, Buffer buffer, int offset, int length, int position, |
| 374 [FsWriteCallback callback]) |
| 375 native "this._fs.write(fd, buffer, offset, length, position, callback);"; |
| 376 int writeBufferSync(int fd, Buffer buffer, int offset, int length, int |
| 377 position) |
| 378 native |
| 379 "return this._fs.writeBufferSync(fd, buffer, offset, length, position)
;"; |
| 380 int writeSync(int fd, String str, [int position, String encoding='utf8']) |
| 381 native "return this._fs.writeSync(fd, str, position, encoding);"; |
| 382 |
| 383 void read(int fd, String buffer, int offset, int length, int position, |
| 384 [FsReadCallback callback]) |
| 385 native "this._fs.read(fd, buffer, offset, length, position, callback);"; |
| 386 int readBufferSync(int fd, String buffer, int offset, int length, int position |
| 387 ) |
| 388 native "return this._fs.readSync(fd, buffer, offset, length, position);"; |
| 389 String readSync(int fd, int length, int position, String encoding) |
| 390 native "return this._fs.readSync(fd, length, position, encoding);"; |
| 391 |
| 392 void readFile(String filename, [String encoding= |
| 393 'utf8', FsReadFileCallback callback]) |
| 394 native "this._fs.readFile(filename, encoding, callback);"; |
| 395 String readFileSync(String filename, [String encoding='utf8']) |
| 396 native "return this._fs.readFileSync(filename, encoding);"; |
| 397 |
| 398 void readFileBuffer(String filename, [FsReadFileBufferCallback callback]) |
| 399 native "this._fs.readFile(filename, callback);"; |
| 400 Buffer readFileBufferSync(String filename) |
| 401 native "return this._fs.readFileSync(filename);"; |
| 402 |
| 403 void writeFile(String filename, String data, [String encoding= |
| 404 'utf8', FsWriteFileCallback callback]) |
| 405 native "this._fs.writeFile(filename, data, encoding, callback);"; |
| 406 void writeFileSync(String filename, String data, [String encoding='utf8']) |
| 407 native "this._fs.writeFileSync(filename, data, encoding);"; |
| 408 |
| 409 void writeFileBuffer(String filename, Buffer data, [FsWriteFileBufferCallback |
| 410 callback]) |
| 411 native "this._fs.writeFile(filename, data, callback);"; |
| 412 void writeFileBufferSync(String filename, Buffer data) |
| 413 native "this._fs.writeFile(filename, data);"; |
| 414 |
| 415 void watchFile(String filename, FsWatchFileListener listener, [Map options]) |
| 416 native "this._fs.watchFile(filename, options, listener);"; |
| 417 void unwatchFile(String filename) |
| 418 native "this._fs.unwatchFile(filename);"; |
| 419 FSWatcher watch(String filename, FSWatcherChangeListener listener, [Map |
| 420 options]) |
| 421 native "return this._fs.watch(filename, options, listener);"; |
| 422 |
| 423 ReadStream createReadStream(String path, [Map options]) |
| 424 native "return this._fs.createReadStream(path, options);"; |
| 425 WriteStream createWriteStream(String path, [Map options]) |
| 426 native "return this._fs.createWriteStream(path, options);"; |
| 427 } |
| 428 |
| 429 Fs get fs() => require('fs'); |
| 430 |
| 431 class Stats native "fs.Stats" { |
| 432 bool isFile() native; |
| 433 bool isDirectory() native; |
| 434 bool isBlockDevice() native; |
| 435 bool isCharacterDevice() native; |
| 436 bool isSymbolicLink() native; |
| 437 bool isFIFO() native; |
| 438 bool isSocket() native; |
| 439 |
| 440 int dev; |
| 441 int ino; |
| 442 int mode; |
| 443 int nlink; |
| 444 int uid; |
| 445 int gid; |
| 446 int rdev; |
| 447 int size; |
| 448 int blksize; |
| 449 int blocks; |
| 450 Date atime; |
| 451 Date mtime; |
| 452 Date ctime; |
| 453 } |
| 454 |
| 455 typedef void FSWatcherErrorListener(Error err); |
| 456 typedef void FSWatcherChangeListener(String event, String filename); |
| 457 |
| 458 class FSWatcher native "*FSWatcher" { |
| 459 void close() native; |
| 460 |
| 461 // EventEmitter |
| 462 void removeAllListeners(String event) |
| 463 native "this._writeStream.removeAllListeners(event);"; |
| 464 void setMaxListeners(num n) native; |
| 465 var _listeners(String key) |
| 466 native "return this.listeners(key);"; |
| 467 |
| 468 // Error event |
| 469 void emitError(Error error) |
| 470 native "this.emit('error', error);"; |
| 471 void addListenerError(FSWatcherErrorListener listener) |
| 472 native "this.addListener('error', listener);"; |
| 473 void onError(FSWatcherErrorListener listener) |
| 474 native "this.on('error', listener);"; |
| 475 void onceError(FSWatcherErrorListener listener) |
| 476 native "this.once('error', listener);"; |
| 477 void removeListenerError(FSWatcherErrorListener listener) |
| 478 native "this.removeListener('error', listener);"; |
| 479 List<FSWatcherErrorListener> listenersError() |
| 480 => new _NativeListPrimitiveElement<FSWatcherErrorListener>(_listeners( |
| 481 'error')); |
| 482 |
| 483 // Change event |
| 484 void emitChange(String event, String filename) |
| 485 native "this.emit('change', event, filename);"; |
| 486 void addListenerChange(FSWatcherChangeListener listener) |
| 487 native "this.addListener('change', listener);"; |
| 488 void onChange(FSWatcherChangeListener listener) |
| 489 native "this.on('change', listener);"; |
| 490 void onceChange(FSWatcherChangeListener listener) |
| 491 native "this.once('change', listener);"; |
| 492 void removeListenerChange(FSWatcherChangeListener listener) |
| 493 native "this.removeListener('change', listener);"; |
| 494 List<FSWatcherChangeListener> listenersChange() |
| 495 => new _NativeListPrimitiveElement<FSWatcherChangeListener>(_listeners( |
| 496 'change')); |
| 497 } |
OLD | NEW |