fs/lib/AbstractReaderWriter.js

  1. const AbstractReader = require("./AbstractReader");
  2. /**
  3. * Abstract resource locator
  4. *
  5. * @public
  6. * @abstract
  7. * @memberof module:@ui5/fs
  8. * @augments module:@ui5/fs.AbstractReader
  9. */
  10. class AbstractReaderWriter extends AbstractReader {
  11. /**
  12. * The constructor.
  13. *
  14. * @public
  15. */
  16. constructor() {
  17. if (new.target === AbstractReaderWriter) {
  18. throw new TypeError("Class 'AbstractReaderWriter' is abstract");
  19. }
  20. super();
  21. }
  22. /**
  23. * Writes the content of a resource to a path.
  24. *
  25. * @public
  26. * @param {module:@ui5/fs.Resource} resource Resource to write
  27. * @param {object} [options]
  28. * @param {boolean} [options.readOnly=false] Whether the resource content shall be written read-only
  29. * Do not use in conjunction with the <code>drain</code> option.
  30. * The written file will be used as the new source of this resources content.
  31. * Therefore the written file should not be altered by any means.
  32. * Activating this option might improve overall memory consumption.
  33. * @param {boolean} [options.drain=false] Whether the resource content shall be emptied during the write process.
  34. * Do not use in conjunction with the <code>readOnly</code> option.
  35. * Activating this option might improve overall memory consumption.
  36. * This should be used in cases where this is the last access to the resource.
  37. * E.g. the final write of a resource after all processing is finished.
  38. * @returns {Promise<undefined>} Promise resolving once data has been written
  39. */
  40. write(resource, options = {drain: false, readOnly: false}) {
  41. return this._write(resource, options);
  42. }
  43. /**
  44. * Writes the content of a resource to a path.
  45. *
  46. * @abstract
  47. * @protected
  48. * @param {module:@ui5/fs.Resource} resource Resource to write
  49. * @param {object} [options] Write options, see above
  50. * @returns {Promise<undefined>} Promise resolving once data has been written
  51. */
  52. _write(resource, options) {
  53. throw new Error("Not implemented");
  54. }
  55. }
  56. module.exports = AbstractReaderWriter;