|
@@ -22,6 +22,23 @@ ErrorOr<Reader> Reader::create(MaybeOwned<BoxStream> stream)
|
|
|
}
|
|
|
|
|
|
ErrorOr<BoxList> Reader::read_entire_file()
|
|
|
+{
|
|
|
+ auto make_top_level_box = [](BoxType type, BoxStream& stream) -> ErrorOr<Optional<NonnullOwnPtr<Box>>> {
|
|
|
+ switch (type) {
|
|
|
+ case BoxType::FileTypeBox:
|
|
|
+ return TRY(FileTypeBox::create_from_stream(stream));
|
|
|
+ case BoxType::JPEG2000HeaderBox:
|
|
|
+ return TRY(JPEG2000HeaderBox::create_from_stream(stream));
|
|
|
+ case BoxType::JPEG2000SignatureBox:
|
|
|
+ return TRY(JPEG2000SignatureBox::create_from_stream(stream));
|
|
|
+ default:
|
|
|
+ return OptionalNone {};
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return read_entire_file((ErrorOr<Optional<NonnullOwnPtr<Box>>>(*)(BoxType, BoxStream&))(make_top_level_box));
|
|
|
+}
|
|
|
+
|
|
|
+ErrorOr<BoxList> Reader::read_entire_file(BoxCallback box_factory)
|
|
|
{
|
|
|
BoxList top_level_boxes;
|
|
|
|
|
@@ -29,19 +46,11 @@ ErrorOr<BoxList> Reader::read_entire_file()
|
|
|
auto box_header = TRY(read_box_header(*m_box_stream));
|
|
|
BoxStream box_stream { MaybeOwned<Stream> { *m_box_stream }, static_cast<size_t>(box_header.contents_size) };
|
|
|
|
|
|
- switch (box_header.type) {
|
|
|
- case BoxType::FileTypeBox:
|
|
|
- TRY(top_level_boxes.try_append(TRY(FileTypeBox::create_from_stream(box_stream))));
|
|
|
- break;
|
|
|
- case BoxType::JPEG2000HeaderBox:
|
|
|
- TRY(top_level_boxes.try_append(TRY(JPEG2000HeaderBox::create_from_stream(box_stream))));
|
|
|
- break;
|
|
|
- case BoxType::JPEG2000SignatureBox:
|
|
|
- TRY(top_level_boxes.try_append(TRY(JPEG2000SignatureBox::create_from_stream(box_stream))));
|
|
|
- break;
|
|
|
- default:
|
|
|
+ auto maybe_box = TRY(box_factory(box_header.type, box_stream));
|
|
|
+ if (maybe_box.has_value()) {
|
|
|
+ TRY(top_level_boxes.try_append(move(maybe_box.value())));
|
|
|
+ } else {
|
|
|
TRY(top_level_boxes.try_append(TRY(UnknownBox::create_from_stream(box_header.type, box_stream))));
|
|
|
- break;
|
|
|
}
|
|
|
|
|
|
if (!box_stream.is_eof())
|