FileSystem.hx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (C)2005-2018 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package lua.lib.luv.fs;
  23. import lua.lib.luv.fs.Open;
  24. import lua.Result;
  25. @:luaRequire("luv")
  26. extern class FileSystem {
  27. @:native("fs_close")
  28. @:overload(function(file : FileDescriptor, cb : String->Bool->Void) : Request {})
  29. static function close(file : FileDescriptor) : Result<Bool>;
  30. @:native("fs_open")
  31. @:overload(function(path : String, flags : Open, mode : Int, ?cb : String->FileDescriptor->Void) : Request {})
  32. static function open(path : String, flags : Open, mode : Int) : Result<FileDescriptor>;
  33. @:native("fs_read")
  34. @:overload(function(file : FileDescriptor, len : Int, offset : Int, ?cb : String->String->Void) : Request {} )
  35. static function read(file : FileDescriptor, len : Int, offset : Int) : Result<String>;
  36. @:native("fs_unlink")
  37. @:overload(function(file : FileDescriptor, ?cb : String->String->Void) : Request {} )
  38. static function unlink(file : FileDescriptor, content : String) : Result<String>;
  39. @:native("fs_write")
  40. @:overload(function(file : FileDescriptor, content : String, offset : Int, ?cb : String->Bool->Void) : Int {})
  41. static function write(file : FileDescriptor, content : String, offset : Int) : Result<Bool>;
  42. @:native("fs_mkdir")
  43. @:overload(function(path : String, mode : Int, cb : String->Bool->Void) : Request {})
  44. static function mkdir(path : String, mode :Int) : Result<Bool>;
  45. @:native("fs_mkdtemp")
  46. @:overload(function(data : String, cb : String->Bool->Void) : Request {})
  47. static function mkdtemp(data : String) : Result<Bool>;
  48. @:native("fs_rmdir")
  49. @:overload(function(path : String, cb : String->Bool->Void) : Request {})
  50. static function rmdir(path : String) : Result<Int>;
  51. @:native("fs_scandir")
  52. @:overload(function(path : String, cb : String->Bool->Void) : Request {})
  53. static function scandir(path : String) : ScanDirMarker;
  54. @:native("fs_scandir_next")
  55. static function scandir_next(scandir : ScanDirMarker) : ScandirNext;
  56. @:native("fs_stat")
  57. @:overload(function(path : String, cb : String->Stat->Void) : Request {})
  58. static function stat(path : String) : Result<Stat>;
  59. @:native("fs_fstat")
  60. @:overload(function(descriptor : FileDescriptor, cb : String->Stat->Void) : Request {})
  61. static function fstat(descriptor : FileDescriptor) : Result<Stat>;
  62. @:native("fs_lstat")
  63. @:overload(function(path : String, cb : String->Stat->Void) : Request {})
  64. static function lstat(path : String) : Result<Stat>;
  65. @:native("fs_rename")
  66. @:overload(function(path : String, newpath : String, cb : String->Bool->Void) : Request {})
  67. static function rename(path : String, newpath : String) : Result<Bool>;
  68. @:native("fs_fsync")
  69. @:overload(function(descriptor : FileDescriptor, cb : String->Bool->Void) : Request {})
  70. static function fsync(descriptor : FileDescriptor) : Result<Bool>;
  71. @:native("fs_fdatasync")
  72. @:overload(function(descriptor : FileDescriptor, cb : String->Bool->Void) : Request {})
  73. static function fdatasync(descriptor : FileDescriptor) : Result<Bool>;
  74. @:native("fs_ftruncate")
  75. @:overload(function(descriptor : FileDescriptor, offset : Int, cb : String->Bool->Void) : Request {})
  76. static function ftruncate(descriptor : FileDescriptor, offset : Int) : Result<Bool>;
  77. @:native("fs_sendfile")
  78. @:overload(function(fin : FileDescriptor, fout : FileDescriptor, cb : String->Int->Void) : Request {})
  79. static function sendfile(fin : FileDescriptor, fout : FileDescriptor) : Result<Int>;
  80. @:native("fs_access")
  81. @:overload(function(path : String, mode : Int, cb : String->Bool->Void) : Request {})
  82. static function access(path : String, mode :Int) : Result<Bool>;
  83. @:native("fs_chmod")
  84. @:overload(function(path : String, mode : Int, cb : String->Bool->Void) : Request {})
  85. static function chmod(path : String, mode :Int) : Result<Bool>;
  86. @:native("fs_fchmod")
  87. @:overload(function(descriptor : FileDescriptor, mode : Int, cb : String->Bool->Void) : Request {})
  88. static function fchmod(descriptor : FileDescriptor, mode :Int) : Result<Bool>;
  89. @:native("fs_futime")
  90. @:overload(function(descriptor : FileDescriptor, actime : Int, modtime : Int, cb : String->Bool->Void) : Request {})
  91. static function futime(descriptor : FileDescriptor, actime : Int, modtime : Int) : Result<Bool>;
  92. @:native("fs_utime")
  93. @:overload(function(path : String, actime : Int, modtime : Int, cb : String->Bool->Void) : Request {})
  94. static function utime(path : String, actime : Int, modtime : Int) : Result<Bool>;
  95. @:native("fs_link")
  96. @:overload(function(oldpath : String, newpath : String, cb : String->Bool->Void) : Request {})
  97. static function link(oldpath : String, newpath : String) : Result<Bool>;
  98. @:native("fs_symlink")
  99. @:overload(function(oldpath : String, newpath : String, flags : Int, cb : String->Bool->Void) : Request {})
  100. static function symlink(oldpath : String, newpath : String, flags : Int) : Bool;
  101. // @:native("fs_readlink")
  102. // @:overload(function(path : String, cb : String->String->Void) : Request {})
  103. // static function readlink(path : String) : String;
  104. @:native("fs_realpath")
  105. @:overload(function(path : String, cb : String->String->Void) : Request{})
  106. static function realpath(path : String) : String;
  107. @:native("fs_chown")
  108. @:overload(function(path : String, uid : Int, gid : Int, cb : String->Bool->Void) : Request {})
  109. static function chown(path : String, uid : Int, gid : Int) : Bool;
  110. @:native("fs_fchown")
  111. @:overload(function(descriptor : FileDescriptor, uid : Int, gid : Int, cb : String->Bool->Void) : Request {})
  112. static function fchown(descriptor : FileDescriptor, uid : Int, gid : Int) : Bool;
  113. }
  114. extern class ScanDirMarker {}
  115. @:multiReturn
  116. extern class ScandirNext {
  117. var name : String;
  118. var type : String;
  119. }
  120. typedef Stat = {
  121. ino : Int,
  122. ctime : TimeStamp,
  123. uid : Int,
  124. dev : Int,
  125. nlink : Int,
  126. mode : Int,
  127. size : Int,
  128. birthtime : TimeStamp,
  129. gid : Int,
  130. type : String,
  131. rdev : Int,
  132. gen : Int,
  133. blocks : Int,
  134. mtime : TimeStamp,
  135. atime : TimeStamp,
  136. blksize : Int,
  137. flags : Int
  138. }
  139. typedef TimeStamp = {
  140. sec : Int,
  141. nsec : Int
  142. }