/src/serenity/Userland/Libraries/LibRIFF/Decoding.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org> |
3 | | * Copyright (c) 2023, Nicolas Ramz <nicolas.ramz@gmail.com> |
4 | | * Copyright (c) 2023, Nico Weber <thakis@chromium.org> |
5 | | * |
6 | | * SPDX-License-Identifier: BSD-2-Clause |
7 | | */ |
8 | | |
9 | | #include <AK/Stream.h> |
10 | | #include <LibRIFF/ChunkID.h> |
11 | | #include <LibRIFF/RIFF.h> |
12 | | |
13 | | ErrorOr<RIFF::ChunkID> RIFF::ChunkID::read_from_stream(Stream& stream) |
14 | 862k | { |
15 | 862k | Array<u8, chunk_id_size> id; |
16 | 862k | TRY(stream.read_until_filled(id.span())); |
17 | 860k | return ChunkID { id }; |
18 | 862k | } |
19 | | |
20 | | ErrorOr<RIFF::OwnedList> RIFF::OwnedList::read_from_stream(Stream& stream) |
21 | 61.4k | { |
22 | 61.4k | auto type = TRY(stream.read_value<ChunkID>()); |
23 | 60.8k | Vector<RIFF::OwnedChunk> chunks; |
24 | 518k | while (!stream.is_eof()) |
25 | 462k | TRY(chunks.try_append(TRY(stream.read_value<RIFF::OwnedChunk>()))); |
26 | | |
27 | 60.8k | return RIFF::OwnedList { .type = type, .chunks = move(chunks) }; |
28 | 60.8k | } |