File.hx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package asys.io;
  2. import haxe.io.Bytes;
  3. import haxe.io.Encoding;
  4. import asys.*;
  5. /**
  6. Class representing an open file. Some methods in this class are instance
  7. variants of the same methods in `asys.FileSystem`.
  8. **/
  9. extern class File {
  10. private function get_async():AsyncFile;
  11. var async(get, never):AsyncFile;
  12. /**
  13. See `asys.FileSystem.chmod`.
  14. **/
  15. function chmod(mode:FilePermissions):Void;
  16. /**
  17. See `asys.FileSystem.chown`.
  18. **/
  19. function chown(uid:Int, gid:Int):Void;
  20. /**
  21. Closes the file. Any operation after this method is called is invalid.
  22. **/
  23. function close():Void;
  24. /**
  25. Same as `sync`, but metadata is not flushed unless needed for subsequent
  26. data reads to be correct. E.g. changes to the modification times are not
  27. flushed, but changes to the filesize do.
  28. **/
  29. function datasync():Void;
  30. /**
  31. Reads a part of `this` file into the given `buffer`.
  32. @param buffer Buffer to which data will be written.
  33. @param offset Position in `buffer` at which to start writing.
  34. @param length Number of bytes to read from `this` file.
  35. @param position Position in `this` file at which to start reading.
  36. **/
  37. function readBuffer(buffer:Bytes, offset:Int, length:Int, position:Int):{bytesRead:Int, buffer:Bytes};
  38. /**
  39. Reads the entire contents of `this` file.
  40. **/
  41. function readFile():Bytes;
  42. /**
  43. See `asys.FileSystem.stat`.
  44. **/
  45. function stat():FileStat;
  46. /**
  47. Flushes all modified data and metadata of `this` file to the disk.
  48. **/
  49. function sync():Void;
  50. /**
  51. See `asys.FileSystem.truncate`.
  52. **/
  53. function truncate(?len:Int = 0):Void;
  54. /**
  55. See `asys.FileSystem.utimes`.
  56. **/
  57. function utimes(atime:Date, mtime:Date):Void;
  58. /**
  59. Writes a part of the given `buffer` into `this` file.
  60. @param buffer Buffer from which data will be read.
  61. @param offset Position in `buffer` at which to start reading.
  62. @param length Number of bytes to write to `this` file.
  63. @param position Position in `this` file at which to start writing.
  64. **/
  65. function writeBuffer(buffer:Bytes, offset:Int, length:Int, position:Int):{bytesWritten:Int, buffer:Bytes};
  66. /**
  67. Writes a string to `this` file at `position`.
  68. **/
  69. function writeString(str:String, ?position:Int, ?encoding:Encoding):{bytesWritten:Int, buffer:Bytes};
  70. }