AsyncFile.hx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package asys.io;
  2. import haxe.Error;
  3. import haxe.NoData;
  4. import haxe.async.*;
  5. import haxe.io.Bytes;
  6. import haxe.io.Encoding;
  7. import asys.*;
  8. /**
  9. This class provides methods for asynchronous operations on files instances.
  10. For synchronous operations, see `asys.io.File`. To obtain an instance of
  11. this class, use the `async` field of `asys.io.File`.
  12. ```haxe
  13. var file = asys.FileSystem.open("example.txt", "r");
  14. file.async.readFile(contents -> trace(contents.toString()));
  15. ```
  16. All methods here are asynchronous versions of the functions in
  17. `asys.io.File`. Please see them for a description of the arguments and
  18. use of each method.
  19. Any synchronous method that returns no value (`Void` return type) has an
  20. extra `callback:Callback<NoData>` argument.
  21. Any synchronous method that returns a value has an extra
  22. `callback:Callback<T>` argument, where `T` is the return type of the
  23. synchronous method.
  24. Errors are communicated through the callbacks or in some cases thrown
  25. immediately.
  26. **/
  27. extern class AsyncFile {
  28. function chmod(mode:FilePermissions, callback:Callback<NoData>):Void;
  29. function chown(uid:Int, gid:Int, callback:Callback<NoData>):Void;
  30. function close(callback:Callback<NoData>):Void;
  31. function datasync(callback:Callback<NoData>):Void;
  32. function readBuffer(buffer:Bytes, offset:Int, length:Int, position:Int, callback:Callback<{bytesRead:Int, buffer:Bytes}>):Void;
  33. function readFile(callback:Callback<Bytes>):Void;
  34. function stat(callback:Callback<FileStat>):Void;
  35. function sync(callback:Callback<NoData>):Void;
  36. function truncate(?len:Int = 0, callback:Callback<NoData>):Void;
  37. function utimes(atime:Date, mtime:Date, callback:Callback<NoData>):Void;
  38. function writeBuffer(buffer:Bytes, offset:Int, length:Int, position:Int, callback:Callback<{bytesWritten:Int, buffer:Bytes}>):Void;
  39. function writeString(str:String, ?position:Int, ?encoding:Encoding, callback:Callback<{bytesWritten:Int, buffer:Bytes}>):Void;
  40. }