[FL-2655, FL-2650] Buffered file streams (#1424)
* Initial buffered file stream implementation * Fix logical errors * Fix more logical errors * Minimally working implementation * Adapt infrared unit tests for buffered streams * Increase read buffer size from 512 to 1K * Correct naming and formatting * More code improvements * Allow passing access and open modes for buffered streams * Implement tests for buffered streams * Better file and method names * Add comments and correct formatting * Use buffered streams in Infrared * Fix compilation error
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <toolbox/stream/string_stream.h>
|
||||
#include <toolbox/stream/file_stream.h>
|
||||
#include <toolbox/stream/buffered_file_stream.h>
|
||||
#include "flipper_format.h"
|
||||
#include "flipper_format_i.h"
|
||||
#include "flipper_format_stream.h"
|
||||
@@ -36,11 +37,24 @@ FlipperFormat* flipper_format_file_alloc(Storage* storage) {
|
||||
return flipper_format;
|
||||
}
|
||||
|
||||
FlipperFormat* flipper_format_buffered_file_alloc(Storage* storage) {
|
||||
FlipperFormat* flipper_format = malloc(sizeof(FlipperFormat));
|
||||
flipper_format->stream = buffered_file_stream_alloc(storage);
|
||||
flipper_format->strict_mode = false;
|
||||
return flipper_format;
|
||||
}
|
||||
|
||||
bool flipper_format_file_open_existing(FlipperFormat* flipper_format, const char* path) {
|
||||
furi_assert(flipper_format);
|
||||
return file_stream_open(flipper_format->stream, path, FSAM_READ_WRITE, FSOM_OPEN_EXISTING);
|
||||
}
|
||||
|
||||
bool flipper_format_buffered_file_open_existing(FlipperFormat* flipper_format, const char* path) {
|
||||
furi_assert(flipper_format);
|
||||
return buffered_file_stream_open(
|
||||
flipper_format->stream, path, FSAM_READ_WRITE, FSOM_OPEN_EXISTING);
|
||||
}
|
||||
|
||||
bool flipper_format_file_open_append(FlipperFormat* flipper_format, const char* path) {
|
||||
furi_assert(flipper_format);
|
||||
|
||||
@@ -87,6 +101,11 @@ bool flipper_format_file_close(FlipperFormat* flipper_format) {
|
||||
return file_stream_close(flipper_format->stream);
|
||||
}
|
||||
|
||||
bool flipper_format_buffered_file_close(FlipperFormat* flipper_format) {
|
||||
furi_assert(flipper_format);
|
||||
return buffered_file_stream_close(flipper_format->stream);
|
||||
}
|
||||
|
||||
void flipper_format_free(FlipperFormat* flipper_format) {
|
||||
furi_assert(flipper_format);
|
||||
stream_free(flipper_format->stream);
|
||||
|
Reference in New Issue
Block a user