Dir.hx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package eval.luv;
  2. import eval.luv.File;
  3. enum abstract DirentKind(Int) {
  4. var UNKNOWN = 0;
  5. var FILE = 1;
  6. var DIR = 2;
  7. var LINK = 3;
  8. var FIFO = 4;
  9. var SOCKET = 5;
  10. var CHAR = 6;
  11. var BLOCK = 7;
  12. }
  13. typedef Dirent = {
  14. var kind:DirentKind;
  15. var name:NativeString;
  16. }
  17. typedef DirectoryScan = {
  18. /**
  19. Retrieves the next directory entry.
  20. **/
  21. function next():Null<Dirent>;
  22. /**
  23. Cleans up after a directory scan.
  24. **/
  25. function end():Void;
  26. }
  27. /**
  28. @see https://aantron.github.io/luv/luv/Luv/File#module-Dir
  29. **/
  30. @:coreType abstract Dir {
  31. /**
  32. Opens the directory at the given path for listing.
  33. **/
  34. static public function open(loop:Loop, path:NativeString, ?request:FileRequest, callback:(result:Result<Dir>)->Void):Void;
  35. /**
  36. Closes the directory.
  37. **/
  38. public function close(loop:Loop, ?request:FileRequest, callback:(result:Result<Result.NoData>)->Void):Void;
  39. /**
  40. Retrieves a directory entry.
  41. **/
  42. public function read(loop:Loop, ?numberOfEntries:Int, ?request:FileRequest, callback:(result:Result<Array<Dirent>>)->Void):Void;
  43. /**
  44. Begins directory listing.
  45. **/
  46. static public function scan(loop:Loop, path:NativeString, ?request:FileRequest, callback:(result:Result<DirectoryScan>)->Void):Void;
  47. }
  48. /**
  49. Synchronous version of `eval.luv.Dir` API
  50. **/
  51. extern class DirSync {
  52. @:inheritDoc(eval.luv.Dir.open)
  53. static public function open(path:NativeString):Result<Dir>;
  54. @:inheritDoc(eval.luv.Dir.close)
  55. static public function close(dir:Dir):Result<Result.NoData>;
  56. @:inheritDoc(eval.luv.Dir.read)
  57. static public function read(dir:Dir, ?numberOfEntries:Int):Result<Array<Dirent>>;
  58. @:inheritDoc(eval.luv.Dir.scan)
  59. static public function scan(path:NativeString):Result<DirectoryScan>;
  60. }