1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

LibAudio: Remove the last occurrence of Core::File in the Flac plugin

The design is deeply inspired from what is done in the Wav plugin.
This commit is contained in:
Lucas CHOLLET 2022-10-13 12:13:15 +02:00 committed by Linus Groh
parent f028930033
commit 597a614ce6
2 changed files with 8 additions and 20 deletions

View file

@ -26,33 +26,21 @@
namespace Audio {
FlacLoaderPlugin::FlacLoaderPlugin(StringView path)
: m_file(Core::File::construct(path))
: m_path(path)
{
if (!m_file->open(Core::OpenMode::ReadOnly)) {
m_error = LoaderError { String::formatted("Can't open file: {}", m_file->error_string()) };
return;
}
auto maybe_stream = Core::Stream::BufferedFile::create(MUST(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)), FLAC_BUFFER_SIZE);
if (maybe_stream.is_error())
m_error = LoaderError { "Can't open file stream" };
else
m_stream = maybe_stream.release_value();
}
FlacLoaderPlugin::FlacLoaderPlugin(Bytes& buffer)
: m_backing_memory(buffer)
{
auto maybe_stream = Core::Stream::MemoryStream::construct(buffer);
if (maybe_stream.is_error())
m_error = LoaderError { "Can't open memory stream" };
else
m_stream = maybe_stream.release_value();
}
MaybeLoaderError FlacLoaderPlugin::initialize()
{
if (m_error.has_value())
return m_error.release_value();
if (m_backing_memory.has_value())
m_stream = LOADER_TRY(Core::Stream::MemoryStream::construct(m_backing_memory.value()));
else
m_stream = LOADER_TRY(Core::Stream::File::open(m_path, Core::Stream::OpenMode::Read));
TRY(parse_header());
TRY(reset());