file.km 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. type File native; // rx.File
  2. type FileReadOnly protected File;
  3. type FileWriteOnly protected File;
  4. type FileReadWrite protected File;
  5. type FileState {
  6. // rx.FileState
  7. name: String,
  8. size: Number,
  9. mode: FileMode,
  10. is-dir: Bool,
  11. mod-time: time::Time
  12. };
  13. type FileMode native;
  14. export function walk-dir:
  15. &(Path) => Observable[(Path,FileState),Error]
  16. native 'walk-dir';
  17. export function list-dir:
  18. &(Path) => Observable[(Path,FileState),Error]
  19. native 'list-dir';
  20. // TODO: use consumer (File -> Async, close on complete) instead of open/close
  21. export function open-read-only:
  22. &(Path) => Async[FileReadOnly,Error]
  23. native 'open-read-only';
  24. export function open-read-write:
  25. &(Path) => Async[FileReadWrite,Error]
  26. native 'open-read-write';
  27. export function open-read-write-create:
  28. &(Path) => Async[FileReadWrite,Error]
  29. native 'open-read-write-create';
  30. export function open-overwrite:
  31. &(Path) => Async[FileWriteOnly,Error]
  32. native 'open-overwrite';
  33. export function open-append:
  34. &(Path) => Async[FileWriteOnly,Error]
  35. native 'open-append';
  36. export function close:
  37. &(File) => Async
  38. native 'file-close';
  39. export function get-state:
  40. &(File) => Async[FileState,Error]
  41. native 'file-get-state';
  42. export function read:
  43. &(FileReadOnly,Number) => Async[Bytes,Error]
  44. native 'file-read';
  45. export function read:
  46. &(FileReadWrite,Number) => Async[Bytes,Error]
  47. native 'file-read';
  48. export function write:
  49. &(FileWriteOnly,Bytes) => Async[unit,Error]
  50. native 'file-write';
  51. export function write:
  52. &(FileReadWrite,Bytes) => Async[unit,Error]
  53. native 'file-write';
  54. export function seek-start:
  55. &(File,Integer) => Async[Integer,Error]
  56. native 'file-seek-start';
  57. export function seek-delta:
  58. &(File,Integer) => Async[Integer,Error]
  59. native 'file-seek-delta';
  60. export function seek-end:
  61. &(File,Integer) => Async[Integer,Error]
  62. native 'file-seek-end';
  63. export function read-char:
  64. &(FileReadOnly) => Async[Char,Error]
  65. native 'file-read-char';
  66. export function read-char:
  67. &(FileReadWrite) => Async[Char,Error]
  68. native 'file-read-char';
  69. export function write-char:
  70. &(FileWriteOnly,Char) => Async[unit,Error]
  71. native 'file-write-char';
  72. export function write-char:
  73. &(FileReadWrite,Char) => Async[unit,Error]
  74. native 'file-write-char';
  75. export function read-string:
  76. &(FileReadOnly) => Async[String,Error]
  77. native 'file-read-string';
  78. export function read-string:
  79. &(FileReadWrite) => Async[String,Error]
  80. native 'file-read-string';
  81. export function write-string:
  82. &(FileWriteOnly,String) => Async[unit,Error]
  83. native 'file-write-string';
  84. export function write-string:
  85. &(FileReadWrite,String) => Async[unit,Error]
  86. native 'file-write-string';
  87. export function read-line:
  88. &(FileReadOnly) => Async[String,Error]
  89. native 'file-read-line';
  90. export function read-line:
  91. &(FileReadWrite) => Async[String,Error]
  92. native 'file-read-line';
  93. export function write-line:
  94. &(FileWriteOnly,String) => Async[unit,Error]
  95. native 'file-write-line';
  96. export function write-line:
  97. &(FileReadWrite,String) => Async[unit,Error]
  98. native 'file-write-line';
  99. export function read-lines:
  100. &(FileReadOnly) => Observable[String,Error]
  101. native 'file-read-lines';
  102. export function read-lines:
  103. &(FileReadWrite) => Observable[String,Error]
  104. native 'file-read-lines';
  105. export function read-all:
  106. &(FileReadOnly) => Async[Bytes,Error]
  107. native 'file-read-all';
  108. export function read-all:
  109. &(FileReadWrite) => Async[Bytes,Error]
  110. native 'file-read-all';