aboutsummaryrefslogtreecommitdiff
path: root/lib/std/pdb.zig
diff options
context:
space:
mode:
authorJonathan Marler <johnnymarler@gmail.com>2020-06-08 22:34:50 -0600
committerAndrew Kelley <andrew@ziglang.org>2020-06-09 13:36:17 -0400
commita282ac7a9119cd0961ea17e29c4a0e9b0baf60d0 (patch)
treea5e8b62dafcdc4fa17ad0dc6ccedf3865a2dd4bc /lib/std/pdb.zig
parent4302f276ed3083b4f261f9e50a9546c9877d2785 (diff)
downloadzig-a282ac7a9119cd0961ea17e29c4a0e9b0baf60d0.tar.gz
zig-a282ac7a9119cd0961ea17e29c4a0e9b0baf60d0.zip
Support Reader for InStream
Diffstat (limited to 'lib/std/pdb.zig')
-rw-r--r--lib/std/pdb.zig16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig
index e4180717e9..62681968a6 100644
--- a/lib/std/pdb.zig
+++ b/lib/std/pdb.zig
@@ -495,7 +495,7 @@ const Msf = struct {
streams: []MsfStream,
fn openFile(self: *Msf, allocator: *mem.Allocator, file: File) !void {
- const in = file.inStream();
+ const in = file.reader();
const superblock = try in.readStruct(SuperBlock);
@@ -528,7 +528,7 @@ const Msf = struct {
);
const begin = self.directory.pos;
- const stream_count = try self.directory.inStream().readIntLittle(u32);
+ const stream_count = try self.directory.reader().readIntLittle(u32);
const stream_sizes = try allocator.alloc(u32, stream_count);
defer allocator.free(stream_sizes);
@@ -537,7 +537,7 @@ const Msf = struct {
// and must be taken into account when resolving stream indices.
const Nil = 0xFFFFFFFF;
for (stream_sizes) |*s, i| {
- const size = try self.directory.inStream().readIntLittle(u32);
+ const size = try self.directory.reader().readIntLittle(u32);
s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);
}
@@ -552,7 +552,7 @@ const Msf = struct {
var blocks = try allocator.alloc(u32, size);
var j: u32 = 0;
while (j < size) : (j += 1) {
- const block_id = try self.directory.inStream().readIntLittle(u32);
+ const block_id = try self.directory.reader().readIntLittle(u32);
const n = (block_id % superblock.BlockSize);
// 0 is for SuperBlock, 1 and 2 for FPMs.
if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > try file.getEndPos())
@@ -647,7 +647,7 @@ const MsfStream = struct {
pub fn readNullTermString(self: *MsfStream, allocator: *mem.Allocator) ![]u8 {
var list = ArrayList(u8).init(allocator);
while (true) {
- const byte = try self.inStream().readByte();
+ const byte = try self.reader().readByte();
if (byte == 0) {
return list.span();
}
@@ -661,7 +661,7 @@ const MsfStream = struct {
var offset = self.pos % self.block_size;
try self.in_file.seekTo(block * self.block_size + offset);
- const in = self.in_file.inStream();
+ const in = self.in_file.reader();
var size: usize = 0;
var rem_buffer = buffer;
@@ -708,6 +708,10 @@ const MsfStream = struct {
return block * self.block_size + offset;
}
+ pub fn reader(self: *MsfStream) std.io.Reader(*MsfStream, Error, read) {
+ return .{ .context = self };
+ }
+ /// Deprecated: use `reader`
pub fn inStream(self: *MsfStream) std.io.InStream(*MsfStream, Error, read) {
return .{ .context = self };
}