-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChunkDataReadStream.cs
More file actions
56 lines (43 loc) · 1.86 KB
/
ChunkDataReadStream.cs
File metadata and controls
56 lines (43 loc) · 1.86 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Runtime.CompilerServices;
namespace EventStore.Plugins.Transforms;
public class ChunkDataReadStream(Stream chunkFileStream) : Stream {
public Stream ChunkFileStream => chunkFileStream;
public sealed override bool CanRead => true;
public sealed override bool CanSeek => true;
public sealed override bool CanWrite => false;
public sealed override void Write(byte[] buffer, int offset, int count) => throw new InvalidOperationException();
public override void Write(ReadOnlySpan<byte> buffer) => throw new InvalidOperationException();
public sealed override void WriteByte(byte value) => throw new InvalidOperationException();
public sealed override void Flush() => throw new InvalidOperationException();
public sealed override void SetLength(long value) => throw new InvalidOperationException();
public override long Length => throw new NotSupportedException();
public sealed override int Read(byte[] buffer, int offset, int count) {
ValidateBufferArguments(buffer, offset, count);
return Read(buffer.AsSpan(offset, count));
}
// reads must always return exactly `Span<byte>.Length` bytes as we never read past the (flushed) writer checkpoint
public override int Read(Span<byte> buffer) => ChunkFileStream.Read(buffer);
public sealed override int ReadByte() {
Unsafe.SkipInit(out byte value);
return Read(new(ref value)) is 1 ? value : -1;
}
// seeks need to support only `SeekOrigin.Begin`
public override long Seek(long offset, SeekOrigin origin) {
if (origin != SeekOrigin.Begin)
throw new NotSupportedException();
return ChunkFileStream.Seek(offset, origin);
}
public override long Position {
get => ChunkFileStream.Position;
set => ChunkFileStream.Position = value;
}
protected override void Dispose(bool disposing) {
try {
if (!disposing)
return;
chunkFileStream.Dispose();
} finally {
base.Dispose(disposing);
}
}
}