1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// SPDX-License-Identifier: MIT
// Copyright (c) 2015-2021 Zig Contributors
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const std = @import("../std.zig");
pub fn SeekableStream(
comptime Context: type,
comptime SeekErrorType: type,
comptime GetSeekPosErrorType: type,
comptime seekToFn: fn (context: Context, pos: u64) SeekErrorType!void,
comptime seekByFn: fn (context: Context, pos: i64) SeekErrorType!void,
comptime getPosFn: fn (context: Context) GetSeekPosErrorType!u64,
comptime getEndPosFn: fn (context: Context) GetSeekPosErrorType!u64,
) type {
return struct {
context: Context,
const Self = @This();
pub const SeekError = SeekErrorType;
pub const GetSeekPosError = GetSeekPosErrorType;
pub fn seekTo(self: Self, pos: u64) SeekError!void {
return seekToFn(self.context, pos);
}
pub fn seekBy(self: Self, amt: i64) SeekError!void {
return seekByFn(self.context, amt);
}
pub fn getEndPos(self: Self) GetSeekPosError!u64 {
return getEndPosFn(self.context);
}
pub fn getPos(self: Self) GetSeekPosError!u64 {
return getPosFn(self.context);
}
};
}
|