From c9d1acf1f1112ea2bd887d967fe87e20a4c7e8f5 Mon Sep 17 00:00:00 2001 From: Trygve Lie Date: Mon, 17 Aug 2026 14:09:48 +0200 Subject: [PATCH] feat: add generation property to ReadFile for CAS write support Adds an opaque generation token to ReadFile that sinks can populate when reading a file. Callers can pass this token back to sink.write() via options.ifGenerationMatch to perform a compare-and-swap write that fails if another writer has modified the file since it was read. --- lib/classes/read-file.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/classes/read-file.js b/lib/classes/read-file.js index 607c5fe8..54bcf530 100644 --- a/lib/classes/read-file.js +++ b/lib/classes/read-file.js @@ -1,11 +1,12 @@ import { isReadableStream } from "../stream.js"; const ReadFile = class ReadFile { - constructor({ mimeType = "", etag = "" } = {}) { + constructor({ mimeType = "", etag = "", generation = "" } = {}) { this._mimeType = mimeType; // @ts-ignore this._stream = undefined; this._etag = etag; + this._generation = generation; } get mimeType() { @@ -27,6 +28,15 @@ const ReadFile = class ReadFile { return this._etag; } + /** + * An opaque version token captured at read time. Pass this back to + * sink.write() as options.ifGenerationMatch to perform a compare-and-swap + * write that fails if another writer has modified the file in the meantime. + */ + get generation() { + return this._generation; + } + get [Symbol.toStringTag]() { return "ReadFile"; }