zynagent-first application framework

Back to the API reference

zyn.Storage#

pub const Storage = struct {
    pub const Blob = Core.Blob;
    pub const Reader = Core.Reader;
    pub const Writer = Core.Writer;
    pub const ServeOptions = Core.ServeOptions;
    pub const Disposition = Core.Disposition;
    pub const UrlOptions = Core.UrlOptions;

    pub const VariantName = std.meta.FieldEnum(@TypeOf(recipes));

    pub const WriteOptions = struct {
        filename: []const u8,
        media_type: []const u8,
        expected_sha256: ?[32]u8 = null,
        variants: []const VariantName = &.{},
    };
    pub const WriterOptions = struct {
        filename: []const u8,
        media_type: []const u8,
        expected_size: u64,
        expected_sha256: ?[32]u8 = null,
        variants: []const VariantName = &.{},
    };

    /// Stores original bytes and atomically queues selected variants with blob metadata.
    pub fn write(self: Storage, contents: []const u8, options: WriteOptions) !Blob;

    /// Starts an atomic write; finishing it queues the selected variants.
    pub fn writer(self: Storage, options: WriterOptions) !Writer;

    /// Queues missing or failed derivatives, reusing pending and ready results.
    pub fn generate_variants(self: Storage, original_id: []const u8, names: []const VariantName) !void;

    /// Looks up a derivative without starting processing or loading the original bytes.
    pub fn variant(self: Storage, original_id: []const u8, name: VariantName) !Core.Variant;

    pub const Transaction = struct {
        /// Purges blob metadata and its derivatives and schedules backend deletion.
        pub fn purge(self: *@This(), blob: Blob) !void;

        pub fn generate_variants(self: *@This(), original_id: []const u8, names: []const VariantName) !void;
    };

    /// Returns stored blob metadata, or null after purging.
    pub fn get(self: Storage, id: []const u8) !?Blob;
    /// Reads complete bytes within the supplied bound and verifies their digest.
    pub fn read(self: Storage, blob: Blob, limit: std.Io.Limit) !?[]const u8;
    /// Opens a stored blob through Zig's reader interface.
    pub fn reader(self: Storage, blob: Blob) !?Reader;
    /// Serves a blob with conditional request handling; requires a response scope.
    pub fn serve(self: Storage, blob: Blob, options: ServeOptions) !Response;
    /// Returns the configured public URL for immutable blob bytes.
    pub fn public_url(self: Storage, blob: Blob, options: UrlOptions) ![]const u8;
    /// Returns a time-limited URL for immutable blob bytes.
    pub fn temporary_url(self: Storage, blob: Blob, lifetime: std.Io.Duration, options: UrlOptions) ![]const u8;
    /// Purges blob metadata and its derivatives and schedules backend deletion.
    pub fn purge(self: *Storage, blob: Blob) !void;
};