2
0

File.hx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 sys.io;
  23. /**
  24. API for reading and writing files.
  25. See `sys.FileSystem` for the complementary file system API.
  26. **/
  27. extern class File {
  28. /**
  29. Retrieves the content of the file specified by `path` as a String.
  30. If the file does not exist or can not be read, an exception is thrown.
  31. `sys.FileSystem.exists` can be used to check for existence.
  32. If `path` is null, the result is unspecified.
  33. **/
  34. static function getContent(path:String):String;
  35. /**
  36. Stores `content` in the file specified by `path`.
  37. If the file cannot be written to, an exception is thrown.
  38. If `path` or `content` are null, the result is unspecified.
  39. **/
  40. static function saveContent(path:String, content:String):Void;
  41. /**
  42. Retrieves the binary content of the file specified by `path`.
  43. If the file does not exist or can not be read, an exception is thrown.
  44. `sys.FileSystem.exists` can be used to check for existence.
  45. If `path` is null, the result is unspecified.
  46. **/
  47. static function getBytes(path:String):haxe.io.Bytes;
  48. /**
  49. Stores `bytes` in the file specified by `path` in binary mode.
  50. If the file cannot be written to, an exception is thrown.
  51. If `path` or `bytes` are null, the result is unspecified.
  52. **/
  53. static function saveBytes(path:String, bytes:haxe.io.Bytes):Void;
  54. /**
  55. Returns an `FileInput` handle to the file specified by `path`.
  56. If `binary` is true, the file is opened in binary mode. Otherwise it is
  57. opened in non-binary mode.
  58. If the file does not exist or can not be read, an exception is thrown.
  59. Operations on the returned `FileInput` handle read on the opened file.
  60. File handles should be closed via `FileInput.close` once the operation
  61. is complete.
  62. If `path` is null, the result is unspecified.
  63. **/
  64. static function read(path:String, binary:Bool = true):FileInput;
  65. /**
  66. Returns an `FileOutput` handle to the file specified by `path`.
  67. If `binary` is true, the file is opened in binary mode. Otherwise it is
  68. opened in non-binary mode.
  69. If the file cannot be written to, an exception is thrown.
  70. Operations on the returned `FileOutput` handle write to the opened file.
  71. If the file existed, its previous content is overwritten.
  72. File handles should be closed via `FileOutput.close` once the operation
  73. is complete.
  74. If `path` is null, the result is unspecified.
  75. **/
  76. static function write(path:String, binary:Bool = true):FileOutput;
  77. /**
  78. Similar to `sys.io.File.write`, but appends to the file if it exists
  79. instead of overwriting its contents.
  80. **/
  81. static function append(path:String, binary:Bool = true):FileOutput;
  82. /**
  83. Similar to `sys.io.File.append`. While `append` can only seek or write
  84. starting from the end of the file's previous contents, `update` can
  85. seek to any position, so the file's previous contents can be
  86. selectively overwritten.
  87. **/
  88. static function update(path:String, binary:Bool = true):FileOutput;
  89. /**
  90. Copies the contents of the file specified by `srcPath` to the file
  91. specified by `dstPath`.
  92. If the `srcPath` does not exist or cannot be read, or if the `dstPath`
  93. file cannot be written to, an exception is thrown.
  94. If the file at `dstPath` exists, its contents are overwritten.
  95. If `srcPath` or `dstPath` are null, the result is unspecified.
  96. **/
  97. static function copy(srcPath:String, dstPath:String):Void;
  98. }