diff --git a/index.js b/index.js index b31105d..e4f9137 100644 --- a/index.js +++ b/index.js @@ -339,16 +339,17 @@ export async function createDelegation (audienceDID, opts) { audienceMeta }) - const { writer, out } = CarWriter.create() - const dest = opts.output ? fs.createWriteStream(opts.output) : process.stdout - - Readable.from(out).pipe(dest) + const result = await delegation.archive() + if (result.error) { + console.error(`Error: failed to archive delegation: ${result.error.message}`) + process.exit(1) + } - for (const block of delegation.export()) { - // @ts-expect-error - await writer.put(block) + if (opts.output) { + await fs.promises.writeFile(opts.output, result.ok) + } else { + process.stdout.write(result.ok) } - await writer.close() } /**