FileSystem.hx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. static final constants:Table<String,Int>;
  28. @:native("fs_close")
  29. @:overload(function(file:FileDescriptor, cb:String->Bool->Void):Request {})
  30. static function close(file:FileDescriptor):Result<Bool>;
  31. @:native("fs_open")
  32. @:overload(function(path:String, flags:Int, mode:Int):Result<FileDescriptor> {})
  33. @:overload(function(path:String, flags:Int, mode:Int, ?cb:String->FileDescriptor->Void):Request {})
  34. @:overload(function(path:String, flags:Open, mode:Int, ?cb:String->FileDescriptor->Void):Request {})
  35. static function open(path:String, flags:Open, mode:Int):Result<FileDescriptor>;
  36. @:native("fs_read")
  37. @:overload(function(file:FileDescriptor, len:Int, offset:Int, ?cb:String->String->Void):Request {})
  38. static function read(file:FileDescriptor, len:Int, offset:Int):Result<String>;
  39. @:native("fs_unlink")
  40. @:overload(function(file:FileDescriptor, ?cb:String->String->Void):Request {})
  41. static function unlink(file:FileDescriptor, content:String):Result<String>;
  42. @:native("fs_write")
  43. @:overload(function(file:FileDescriptor, content:String, offset:Int, ?cb:String->Int->Void):Int {})
  44. static function write(file:FileDescriptor, content:String, offset:Int):Result<Int>;
  45. @:native("fs_mkdir")
  46. @:overload(function(path:String, mode:Int, cb:String->Bool->Void):Request {})
  47. static function mkdir(path:String, mode:Int):Result<Bool>;
  48. @:native("fs_mkdtemp")
  49. @:overload(function(data:String, cb:String->Bool->Void):Request {})
  50. static function mkdtemp(data:String):Result<Bool>;
  51. @:native("fs_rmdir")
  52. @:overload(function(path:String, cb:String->Bool->Void):Request {})
  53. static function rmdir(path:String):Result<Int>;
  54. @:native("fs_scandir")
  55. @:overload(function(path:String, cb:String->Bool->Void):Request {})
  56. static function scandir(path:String):ScanDirMarker;
  57. @:native("fs_scandir_next")
  58. static function scandir_next(scandir:ScanDirMarker):ScandirNext;
  59. @:native("fs_stat")
  60. @:overload(function(path:String, cb:String->Stat->Void):Request {})
  61. static function stat(path:String):Result<Stat>;
  62. @:native("fs_fstat")
  63. @:overload(function(descriptor:FileDescriptor, cb:String->Stat->Void):Request {})
  64. static function fstat(descriptor:FileDescriptor):Result<Stat>;
  65. @:native("fs_lstat")
  66. @:overload(function(path:String, cb:String->Stat->Void):Request {})
  67. static function lstat(path:String):Result<Stat>;
  68. @:native("fs_rename")
  69. @:overload(function(path:String, newpath:String, cb:String->Bool->Void):Request {})
  70. static function rename(path:String, newpath:String):Result<Bool>;
  71. @:native("fs_fsync")
  72. @:overload(function(descriptor:FileDescriptor, cb:String->Bool->Void):Request {})
  73. static function fsync(descriptor:FileDescriptor):Result<Bool>;
  74. @:native("fs_fdatasync")
  75. @:overload(function(descriptor:FileDescriptor, cb:String->Bool->Void):Request {})
  76. static function fdatasync(descriptor:FileDescriptor):Result<Bool>;
  77. @:native("fs_ftruncate")
  78. @:overload(function(descriptor:FileDescriptor, offset:Int, cb:String->Bool->Void):Request {})
  79. static function ftruncate(descriptor:FileDescriptor, offset:Int):Result<Bool>;
  80. @:native("fs_sendfile")
  81. @:overload(function(fin:FileDescriptor, fout:FileDescriptor, cb:String->Int->Void):Request {})
  82. static function sendfile(fin:FileDescriptor, fout:FileDescriptor):Result<Int>;
  83. @:native("fs_access")
  84. @:overload(function(path:String, mode:Int, cb:String->Bool->Void):Request {})
  85. static function access(path:String, mode:Int):Result<Bool>;
  86. @:native("fs_chmod")
  87. @:overload(function(path:String, mode:Int, cb:String->Bool->Void):Request {})
  88. static function chmod(path:String, mode:Int):Result<Bool>;
  89. @:native("fs_fchmod")
  90. @:overload(function(descriptor:FileDescriptor, mode:Int, cb:String->Bool->Void):Request {})
  91. static function fchmod(descriptor:FileDescriptor, mode:Int):Result<Bool>;
  92. @:native("fs_futime")
  93. @:overload(function(descriptor:FileDescriptor, actime:Int, modtime:Int, cb:String->Bool->Void):Request {})
  94. static function futime(descriptor:FileDescriptor, actime:Int, modtime:Int):Result<Bool>;
  95. @:native("fs_utime")
  96. @:overload(function(path:String, actime:Int, modtime:Int, cb:String->Bool->Void):Request {})
  97. static function utime(path:String, actime:Int, modtime:Int):Result<Bool>;
  98. @:native("fs_link")
  99. @:overload(function(oldpath:String, newpath:String, cb:String->Bool->Void):Request {})
  100. static function link(oldpath:String, newpath:String):Result<Bool>;
  101. @:native("fs_symlink")
  102. @:overload(function(oldpath:String, newpath:String, flags:Int, cb:String->Bool->Void):Request {})
  103. static function symlink(oldpath:String, newpath:String, flags:Int):Bool;
  104. @:native("fs_readlink")
  105. @:overload(function(path:String, cb:String->String->Void):Request {})
  106. static function readlink(path:String):String;
  107. @:native("fs_realpath")
  108. @:overload(function(path:String, cb:String->String->Void):Request {})
  109. static function realpath(path:String):String;
  110. @:native("fs_chown")
  111. @:overload(function(path:String, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
  112. static function chown(path:String, uid:Int, gid:Int):Bool;
  113. @:native("fs_fchown")
  114. @:overload(function(descriptor:FileDescriptor, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
  115. static function fchown(descriptor:FileDescriptor, uid:Int, gid:Int):Bool;
  116. /**
  117. Not available on windows
  118. **/
  119. @:native("fs_lchown")
  120. @:overload(function(descriptor:String, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
  121. static function lchown(descriptor:String, uid:Int, gid:Int):Bool;
  122. @:native("fs_copyfile")
  123. @:overload(function(path:String, newPath:String, flags:Null<CopyFlags>, cb:String->Bool->Void):Request {})
  124. static function copyfile(path:String, newPath:String, ?flags:CopyFlags):Bool;
  125. @:native("fs_statfs")
  126. @:overload(function(path:String, cb:StatFs->Bool->Void):Request {})
  127. static function statfs(path:String):StatFs;
  128. @:native("fs_opendir")
  129. @:overload(function(path:String, cb:String->Handle->Void):Request {})
  130. static function opendir(path:String):Handle;
  131. @:native("fs_readdir")
  132. @:overload(function(dir:Handle, cb:String->Table<Int, NameType>->Void):Request {})
  133. static function readdir(path:Handle):Table<Int, NameType>;
  134. @:native("fs_closedir")
  135. @:overload(function(dir:Handle, cb:String->Bool->Void):Request {})
  136. static function closedir(dir:Handle):Bool;
  137. }
  138. extern class ScanDirMarker {}
  139. @:multiReturn
  140. extern class ScandirNext {
  141. var name:String;
  142. var type:String;
  143. }
  144. typedef NameType = {
  145. name:String,
  146. type:String
  147. }
  148. typedef Stat = {
  149. ino:Int,
  150. ctime:TimeStamp,
  151. uid:Int,
  152. dev:Int,
  153. nlink:Int,
  154. mode:Int,
  155. size:Int,
  156. birthtime:TimeStamp,
  157. gid:Int,
  158. type:String,
  159. rdev:Int,
  160. gen:Int,
  161. blocks:Int,
  162. mtime:TimeStamp,
  163. atime:TimeStamp,
  164. blksize:Int,
  165. flags:Int
  166. }
  167. typedef TimeStamp = {
  168. sec:Int,
  169. nsec:Int
  170. }
  171. typedef StatFs = {
  172. type:Int,
  173. bsize:Int,
  174. blocks:Int,
  175. bfree:Int,
  176. bavail:Int,
  177. files:Int,
  178. ffree:Int
  179. }
  180. typedef CopyFlags = {
  181. ?excl:Bool,
  182. ?ficlone:Bool,
  183. ?ficlone_force:Bool
  184. }