FileOpenFlags.hx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package asys;
  2. class FileOpenFlagsImpl {
  3. @:keep public static function fromString(flags:String):FileOpenFlags {
  4. return (switch (flags) {
  5. case "r": ReadOnly;
  6. case "r+": ReadWrite;
  7. case "rs+": ReadWrite | Sync;
  8. case "sr+": ReadWrite | Sync;
  9. case "w": Truncate | Create | WriteOnly;
  10. case "w+": Truncate | Create | ReadWrite;
  11. case "a": Append | Create | WriteOnly;
  12. case "a+": Append | Create | ReadWrite;
  13. case "wx": Truncate | Create | WriteOnly | Excl;
  14. case "xw": Truncate | Create | WriteOnly | Excl;
  15. case "wx+": Truncate | Create | ReadWrite | Excl;
  16. case "xw+": Truncate | Create | ReadWrite | Excl;
  17. case "ax": Append | Create | WriteOnly | Excl;
  18. case "xa": Append | Create | WriteOnly | Excl;
  19. case "as": Append | Create | WriteOnly | Sync;
  20. case "sa": Append | Create | WriteOnly | Sync;
  21. case "ax+": Append | Create | ReadWrite | Excl;
  22. case "xa+": Append | Create | ReadWrite | Excl;
  23. case "as+": Append | Create | ReadWrite | Sync;
  24. case "sa+": Append | Create | ReadWrite | Sync;
  25. case _: throw "invalid file open flags";
  26. });
  27. }
  28. }
  29. /**
  30. Flags used when opening a file with `asys.FileSystem.open` or other file
  31. functions. Specify whether the opened file:
  32. - will be readable
  33. - will be writable
  34. - will be truncated (all data lost) first
  35. - will be in append mode
  36. - will be opened exclusively by this process
  37. Instances of this type can be created by combining flags with the bitwise or
  38. operator:
  39. ```haxe
  40. Truncate | Create | WriteOnly
  41. ```
  42. Well-known combinations of flags can be specified with a string. The
  43. supported modes are: `r`, `r+`, `rs+`, `sr+`, `w`, `w+`, `a`, `a+`, `wx`,
  44. `xw`, `wx+`, `xw+`, `ax`, `xa`, `as`, `sa`, `ax+`, `xa+`, `as+`, `sa+`.
  45. **/
  46. @:native("asys.FileOpenFlagsImpl")
  47. extern enum abstract FileOpenFlags(Int) {
  48. @:from public static function fromString(flags:String):FileOpenFlags;
  49. inline function new(value:Int)
  50. this = value;
  51. inline function get_raw():Int return this;
  52. @:op(A | B)
  53. inline function join(other:FileOpenFlags):FileOpenFlags return new FileOpenFlags(this | other.get_raw());
  54. // TODO: some of these don't make sense in Haxe-wrapped libuv
  55. var Append;
  56. var Create;
  57. var Direct;
  58. var Directory;
  59. var Dsync;
  60. var Excl;
  61. var NoAtime;
  62. var NoCtty;
  63. var NoFollow;
  64. var NonBlock;
  65. var ReadOnly;
  66. var ReadWrite;
  67. var Sync;
  68. var Truncate;
  69. var WriteOnly;
  70. }