UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

49 lines • 2.29 kB
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= import { requireSupported } from "../../cache/context.js"; import { ByteSpool } from "../../io/spool.js"; import { record, startOp } from "../../observe/context.js"; import { VFSName } from "../../types.js"; import { appendByStreamedRewrite } from "../generic/rewrite.js"; import { appendTo } from "./client.js"; import { backendPath } from "./path.js"; import { stat } from "./stat.js"; import { readStream } from "./stream.js"; import { write } from "./write.js"; /** * Add bytes to the end of a file. A file drive9 keeps in object storage takes * them natively, so only its last part and the new bytes move. Any other path * is read and written back whole. The fallback refuses missing-file creation * because its upload cannot enforce create-only, and it refuses directories. */ export async function append(accessor, path, data) { const spool = new ByteSpool(); try { await spool.fill(data); const timer = startOp(); const remote = backendPath(accessor.config, path); if (spool.size > 0 && (await appendTo(accessor, remote, spool))) { record('append', path.virtual, VFSName.TIDB_FILESYSTEM, spool.size, timer); return; } await appendByStreamedRewrite((p) => readStream(accessor, p), (request) => { requireSupported({}, 'tidb_filesystem', request.path, 'put', request.condition); return write(accessor, request.path, request.body); }, (p) => stat(accessor, p), path, spool.stream()); } finally { await spool.close(); } } //# sourceMappingURL=append.js.map