2
0

FileSystem.hx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package lua.lib.luv.fs;
  2. import lua.lib.luv.fs.Open;
  3. import lua.Result;
  4. @:luaRequire("luv")
  5. extern class FileSystem {
  6. @:native("fs_close")
  7. @:overload(function(file : FileDescriptor, cb : String->Bool->Void) : Request {})
  8. static function close(file : FileDescriptor) : Result<Bool>;
  9. @:native("fs_open")
  10. @:overload(function(path : String, flags : Open, mode : Int, ?cb : String->FileDescriptor->Void) : Request {})
  11. static function open(path : String, flags : Open, mode : Int) : Result<FileDescriptor>;
  12. @:native("fs_read")
  13. @:overload(function(file : FileDescriptor, len : Int, offset : Int, ?cb : String->String->Void) : Request {} )
  14. static function read(file : FileDescriptor, len : Int, offset : Int) : Result<String>;
  15. @:native("fs_unlink")
  16. @:overload(function(file : FileDescriptor, ?cb : String->String->Void) : Request {} )
  17. static function unlink(file : FileDescriptor, content : String) : Result<String>;
  18. @:native("fs_write")
  19. @:overload(function(file : FileDescriptor, content : String, offset : Int, ?cb : String->Bool->Void) : Int {})
  20. static function write(file : FileDescriptor, content : String, offset : Int) : Result<Bool>;
  21. @:native("fs_mkdir")
  22. @:overload(function(path : String, mode : Int, cb : String->Bool->Void) : Request {})
  23. static function mkdir(path : String, mode :Int) : Result<Bool>;
  24. @:native("fs_mkdtemp")
  25. @:overload(function(data : String, cb : String->Bool->Void) : Request {})
  26. static function mkdtemp(data : String) : Result<Bool>;
  27. @:native("fs_rmdir")
  28. @:overload(function(path : String, cb : String->Bool->Void) : Request {})
  29. static function rmdir(path : String) : Result<Int>;
  30. @:native("fs_scandir")
  31. @:overload(function(path : String, cb : String->Bool->Void) : Request {})
  32. static function scandir(path : String) : ScanDirMarker;
  33. @:native("fs_scandir_next")
  34. static function scandir_next(scandir : ScanDirMarker) : ScandirNext;
  35. @:native("fs_stat")
  36. @:overload(function(path : String, cb : String->Stat->Void) : Request {})
  37. static function stat(path : String) : Result<Stat>;
  38. @:native("fs_fstat")
  39. @:overload(function(descriptor : FileDescriptor, cb : String->Stat->Void) : Request {})
  40. static function fstat(descriptor : FileDescriptor) : Result<Stat>;
  41. @:native("fs_lstat")
  42. @:overload(function(path : String, cb : String->Stat->Void) : Request {})
  43. static function lstat(path : String) : Result<Stat>;
  44. @:native("fs_rename")
  45. @:overload(function(path : String, newpath : String, cb : String->Bool->Void) : Request {})
  46. static function rename(path : String, newpath : String) : Result<Bool>;
  47. @:native("fs_fsync")
  48. @:overload(function(descriptor : FileDescriptor, cb : String->Bool->Void) : Request {})
  49. static function fsync(descriptor : FileDescriptor) : Result<Bool>;
  50. @:native("fs_fdatasync")
  51. @:overload(function(descriptor : FileDescriptor, cb : String->Bool->Void) : Request {})
  52. static function fdatasync(descriptor : FileDescriptor) : Result<Bool>;
  53. @:native("fs_ftruncate")
  54. @:overload(function(descriptor : FileDescriptor, offset : Int, cb : String->Bool->Void) : Request {})
  55. static function ftruncate(descriptor : FileDescriptor, offset : Int) : Result<Bool>;
  56. @:native("fs_sendfile")
  57. @:overload(function(fin : FileDescriptor, fout : FileDescriptor, cb : String->Int->Void) : Request {})
  58. static function sendfile(fin : FileDescriptor, fout : FileDescriptor) : Result<Int>;
  59. @:native("fs_access")
  60. @:overload(function(path : String, mode : Int, cb : String->Bool->Void) : Request {})
  61. static function access(path : String, mode :Int) : Result<Bool>;
  62. @:native("fs_chmod")
  63. @:overload(function(path : String, mode : Int, cb : String->Bool->Void) : Request {})
  64. static function chmod(path : String, mode :Int) : Result<Bool>;
  65. @:native("fs_fchmod")
  66. @:overload(function(descriptor : FileDescriptor, mode : Int, cb : String->Bool->Void) : Request {})
  67. static function fchmod(descriptor : FileDescriptor, mode :Int) : Result<Bool>;
  68. @:native("fs_futime")
  69. @:overload(function(descriptor : FileDescriptor, actime : Int, modtime : Int, cb : String->Bool->Void) : Request {})
  70. static function futime(descriptor : FileDescriptor, actime : Int, modtime : Int) : Result<Bool>;
  71. @:native("fs_utime")
  72. @:overload(function(path : String, actime : Int, modtime : Int, cb : String->Bool->Void) : Request {})
  73. static function utime(path : String, actime : Int, modtime : Int) : Result<Bool>;
  74. @:native("fs_link")
  75. @:overload(function(oldpath : String, newpath : String, cb : String->Bool->Void) : Request {})
  76. static function link(oldpath : String, newpath : String) : Result<Bool>;
  77. @:native("fs_symlink")
  78. @:overload(function(oldpath : String, newpath : String, flags : Int, cb : String->Bool->Void) : Request {})
  79. static function symlink(oldpath : String, newpath : String, flags : Int) : Bool;
  80. // @:native("fs_readlink")
  81. // @:overload(function(path : String, cb : String->String->Void) : Request {})
  82. // static function readlink(path : String) : String;
  83. @:native("fs_realpath")
  84. @:overload(function(path : String, cb : String->String->Void) : Request{})
  85. static function realpath(path : String) : String;
  86. @:native("fs_chown")
  87. @:overload(function(path : String, uid : Int, gid : Int, cb : String->Bool->Void) : Request {})
  88. static function chown(path : String, uid : Int, gid : Int) : Bool;
  89. @:native("fs_fchown")
  90. @:overload(function(descriptor : FileDescriptor, uid : Int, gid : Int, cb : String->Bool->Void) : Request {})
  91. static function fchown(descriptor : FileDescriptor, uid : Int, gid : Int) : Bool;
  92. }
  93. extern class ScanDirMarker {}
  94. @:multiReturn
  95. extern class ScandirNext {
  96. var name : String;
  97. var type : String;
  98. }
  99. typedef Stat = {
  100. ino : Int,
  101. ctime : TimeStamp,
  102. uid : Int,
  103. dev : Int,
  104. nlink : Int,
  105. mode : Int,
  106. size : Int,
  107. birthtime : TimeStamp,
  108. gid : Int,
  109. type : String,
  110. rdev : Int,
  111. gen : Int,
  112. blocks : Int,
  113. mtime : TimeStamp,
  114. atime : TimeStamp,
  115. blksize : Int,
  116. flags : Int
  117. }
  118. typedef TimeStamp = {
  119. sec : Int,
  120. nsec : Int
  121. }