FileSystem.hx 6.1 KB

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