FileSystem.hx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Copyright (C)2005-2019 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. Not available on windows
  115. **/
  116. @:native("fs_lchown")
  117. @:overload(function(descriptor:FileDescriptor, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
  118. static function lchown(descriptor:FileDescriptor, uid:Int, gid:Int):Bool;
  119. @:native("fs_statfs")
  120. @:overload(function(path:String, cb:StatFs->Bool->Void):Request {})
  121. static function statfs(path:String):StatFs;
  122. @:native("fs_opendir")
  123. @:overload(function(path:String, cb:Handle->Bool->Void):Request {})
  124. static function opendir(path:String):Handle;
  125. @:native("fs_readdir")
  126. @:overload(function(dir:Handle, cb:Table<Int, NameType>->Bool->Void):Request {})
  127. static function readdir(path:String):Table<Int, NameType>;
  128. @:native("fs_closedir")
  129. @:overload(function(dir:Handle, cb:Bool->Void):Request {})
  130. static function closedir(dir:Handle):Bool;
  131. }
  132. extern class ScanDirMarker {}
  133. @:multiReturn
  134. extern class ScandirNext {
  135. var name:String;
  136. var type:String;
  137. }
  138. typedef NameType = {
  139. name:String,
  140. type:String
  141. }
  142. typedef Stat = {
  143. ino:Int,
  144. ctime:TimeStamp,
  145. uid:Int,
  146. dev:Int,
  147. nlink:Int,
  148. mode:Int,
  149. size:Int,
  150. birthtime:TimeStamp,
  151. gid:Int,
  152. type:String,
  153. rdev:Int,
  154. gen:Int,
  155. blocks:Int,
  156. mtime:TimeStamp,
  157. atime:TimeStamp,
  158. blksize:Int,
  159. flags:Int
  160. }
  161. typedef TimeStamp = {
  162. sec:Int,
  163. nsec:Int
  164. }
  165. typedef StatFs = {
  166. type:Int,
  167. bsize:Int,
  168. blocks:Int,
  169. bfree:Int,
  170. bavail:Int,
  171. files:Int,
  172. ffree:Int
  173. }