diff options
Diffstat (limited to 'src/metainfo.zig')
-rw-r--r-- | src/metainfo.zig | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/metainfo.zig b/src/metainfo.zig index cd00438..04e8f64 100644 --- a/src/metainfo.zig +++ b/src/metainfo.zig @@ -12,7 +12,7 @@ pub const Info = struct { md5sum: ?[]const u8 = null, }; - piece_length: u64, + piece_length: u32, pieces: []const u8, files: []File, private: ?bool, @@ -68,7 +68,7 @@ pub const Info = struct { if (ps.len % 20 != 0) return error.Malformatted; return .{ - .piece_length = pl.asInt(u64) catch return error.Malformatted, + .piece_length = pl.asInt(u32) catch return error.Malformatted, .pieces = ps, .files = try files.toOwnedSlice(), .private = priv, @@ -116,10 +116,15 @@ pub const Info = struct { try b.bencode(w); return sha1.finalResult(); } - pub fn pieceHash(self: Info, ix: usize) ?[]const u8 { + pub fn pieceHash(self: Info, ix: usize) ?[20]u8 { const start = 20 * ix; if (start >= self.pieces.len) return null; - return self.pieces[start .. start + 20]; + var res: [20]u8 = undefined; + @memcpy(&res, self.pieces[start .. start + 20]); + return res; + } + pub fn pieceCount(self: Info) u32 { + return @as(u32, @intCast(self.pieces.len)) / 20; } }; |