fs.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import tauri from './tauri'
  2. /**
  3. * reads a file as text
  4. *
  5. * @param {string} filePath path to the file
  6. * @return {Promise<string>}
  7. */
  8. function readTextFile (filePath) {
  9. return tauri.readTextFile(filePath)
  10. }
  11. /**
  12. * reads a file as binary
  13. *
  14. * @param {string} filePath path to the file
  15. * @return {Promise<int[]>}
  16. */
  17. function readBinaryFile (filePath) {
  18. return tauri.readBinaryFile(filePath)
  19. }
  20. /**
  21. * writes a text file
  22. *
  23. * @param {object} file
  24. * @param {string} file.path path of the file
  25. * @param {string} file.contents contents of the file
  26. * @return {Promise<void>}
  27. */
  28. function writeFile (file) {
  29. return tauri.writeFile(file)
  30. }
  31. /**
  32. * @typedef {object} FileEntry
  33. * @property {string} path
  34. * @property {boolean} is_dir
  35. * @property {string} name
  36. */
  37. /**
  38. * list directory files
  39. *
  40. * @param {string} dir path to the directory to read
  41. * @param {object} [options] configuration object
  42. * @param {boolean} [options.recursive] whether to list dirs recursively or not
  43. * @return {Promise<FileEntry[]>}
  44. */
  45. function readDir (dir, options = {}) {
  46. return tauri.readDir(dir, options)
  47. }
  48. export {
  49. readTextFile,
  50. readBinaryFile,
  51. writeFile,
  52. readDir
  53. }