index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict'
  2. const fswin = require('fswin')
  3. const convertAttrs = require('./convertAttrs')
  4. function get (path, callback) {
  5. fswin.getAttributes(path, function (result) {
  6. if (result === undefined) {
  7. // fswin does not return an error -- problem could be ENOENT,EPERM,etc
  8. callback(new Error('unknown error'))
  9. return
  10. }
  11. let attrs = {}
  12. for (let i in result) {
  13. if (i.indexOf('IS_') === 0) {
  14. attrs[i] = result[i]
  15. }
  16. }
  17. callback(null, convertAttrs.from(attrs))
  18. })
  19. }
  20. function getSync (path) {
  21. const result = fswin.getAttributesSync(path)
  22. if (result === undefined) {
  23. // fswin does not return an error -- problem could be ENOENT,EPERM,etc
  24. throw new Error('unknown erorr')
  25. }
  26. return convertAttrs.from(result)
  27. }
  28. function set (path, attrs, callback) {
  29. fswin.setAttributes(path, convertAttrs.to(attrs), function (success) {
  30. // fswin does not return an error -- problem could be ENOENT,EPERM,etc
  31. callback(success === true ? null : new Error('unknown error'))
  32. })
  33. }
  34. function setSync (path, attrs) {
  35. const success = fswin.setAttributesSync(path, convertAttrs.to(attrs))
  36. if (success === false) {
  37. // fswin does not return an error -- problem could be ENOENT,EPERM,etc
  38. throw new Error('unknown erorr')
  39. }
  40. }
  41. module.exports = {
  42. get,
  43. getSync,
  44. set,
  45. setSync,
  46. }