artifact.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var artifact_exports = {};
  20. __export(artifact_exports, {
  21. Artifact: () => Artifact
  22. });
  23. module.exports = __toCommonJS(artifact_exports);
  24. var import_channelOwner = require("./channelOwner");
  25. var import_stream = require("./stream");
  26. var import_fileUtils = require("./fileUtils");
  27. class Artifact extends import_channelOwner.ChannelOwner {
  28. static from(channel) {
  29. return channel._object;
  30. }
  31. async pathAfterFinished() {
  32. if (this._connection.isRemote())
  33. throw new Error(`Path is not available when connecting remotely. Use saveAs() to save a local copy.`);
  34. return (await this._channel.pathAfterFinished()).value;
  35. }
  36. async saveAs(path) {
  37. if (!this._connection.isRemote()) {
  38. await this._channel.saveAs({ path });
  39. return;
  40. }
  41. const result = await this._channel.saveAsStream();
  42. const stream = import_stream.Stream.from(result.stream);
  43. await (0, import_fileUtils.mkdirIfNeeded)(this._platform, path);
  44. await new Promise((resolve, reject) => {
  45. stream.stream().pipe(this._platform.fs().createWriteStream(path)).on("finish", resolve).on("error", reject);
  46. });
  47. }
  48. async failure() {
  49. return (await this._channel.failure()).error || null;
  50. }
  51. async createReadStream() {
  52. const result = await this._channel.stream();
  53. const stream = import_stream.Stream.from(result.stream);
  54. return stream.stream();
  55. }
  56. async readIntoBuffer() {
  57. const stream = await this.createReadStream();
  58. return await new Promise((resolve, reject) => {
  59. const chunks = [];
  60. stream.on("data", (chunk) => {
  61. chunks.push(chunk);
  62. });
  63. stream.on("end", () => {
  64. resolve(Buffer.concat(chunks));
  65. });
  66. stream.on("error", reject);
  67. });
  68. }
  69. async cancel() {
  70. return await this._channel.cancel();
  71. }
  72. async delete() {
  73. return await this._channel.delete();
  74. }
  75. }
  76. // Annotate the CommonJS export names for ESM import in node:
  77. 0 && (module.exports = {
  78. Artifact
  79. });