mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-29 05:40:50 +03:00
new cspot/bell
This commit is contained in:
@@ -1,70 +1,61 @@
|
||||
#include "FileStream.h"
|
||||
|
||||
#include <stdexcept> // for runtime_error
|
||||
|
||||
#include "BellLogger.h" // for bell
|
||||
|
||||
using namespace bell;
|
||||
|
||||
FileStream::FileStream(const std::string& path, std::string read)
|
||||
{
|
||||
file = fopen(path.c_str(), "rb");
|
||||
if (file == NULL)
|
||||
{
|
||||
throw std::runtime_error("Could not open file: " + path);
|
||||
}
|
||||
FileStream::FileStream(const std::string& path, std::string read) {
|
||||
file = fopen(path.c_str(), "rb");
|
||||
if (file == NULL) {
|
||||
throw std::runtime_error("Could not open file: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
FileStream::~FileStream()
|
||||
{
|
||||
close();
|
||||
FileStream::~FileStream() {
|
||||
close();
|
||||
}
|
||||
|
||||
size_t FileStream::read(uint8_t *buf, size_t nbytes)
|
||||
{
|
||||
if (file == NULL)
|
||||
{
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
size_t FileStream::read(uint8_t* buf, size_t nbytes) {
|
||||
if (file == NULL) {
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
|
||||
return fread(buf, 1, nbytes, file);
|
||||
return fread(buf, 1, nbytes, file);
|
||||
}
|
||||
|
||||
size_t FileStream::skip(size_t nbytes)
|
||||
{
|
||||
if (file == NULL)
|
||||
{
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
size_t FileStream::skip(size_t nbytes) {
|
||||
if (file == NULL) {
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
|
||||
return fseek(file, nbytes, SEEK_CUR);
|
||||
return fseek(file, nbytes, SEEK_CUR);
|
||||
}
|
||||
|
||||
size_t FileStream::position()
|
||||
{
|
||||
if (file == NULL)
|
||||
{
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
size_t FileStream::position() {
|
||||
if (file == NULL) {
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
|
||||
return ftell(file);
|
||||
return ftell(file);
|
||||
}
|
||||
|
||||
size_t FileStream::size()
|
||||
{
|
||||
if (file == NULL)
|
||||
{
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
size_t FileStream::size() {
|
||||
if (file == NULL) {
|
||||
throw std::runtime_error("Stream is closed");
|
||||
}
|
||||
|
||||
size_t pos = ftell(file);
|
||||
fseek(file, 0, SEEK_END);
|
||||
size_t size = ftell(file);
|
||||
fseek(file, pos, SEEK_SET);
|
||||
return size;
|
||||
size_t pos = ftell(file);
|
||||
fseek(file, 0, SEEK_END);
|
||||
size_t size = ftell(file);
|
||||
fseek(file, pos, SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
|
||||
void FileStream::close()
|
||||
{
|
||||
if (file != NULL)
|
||||
{
|
||||
fclose(file);
|
||||
file = NULL;
|
||||
}
|
||||
void FileStream::close() {
|
||||
if (file != NULL) {
|
||||
fclose(file);
|
||||
file = NULL;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user