[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:
Georgii Surkov
2022-07-22 19:00:25 +03:00
committed by GitHub
parent ec57dd310a
commit 16e598b2c0
10 changed files with 501 additions and 11 deletions

View File

@@ -0,0 +1,47 @@
#pragma once
#include <stdlib.h>
#include <storage/storage.h>
#include "stream.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Allocate a file stream with buffered read operations
* @return Stream*
*/
Stream* buffered_file_stream_alloc(Storage* storage);
/**
* Opens an existing file or creates a new one.
* @param stream pointer to file stream object.
* @param path path to file
* @param access_mode access mode from FS_AccessMode
* @param open_mode open mode from FS_OpenMode
* @return success flag. You need to close the file even if the open operation failed.
*/
bool buffered_file_stream_open(
Stream* stream,
const char* path,
FS_AccessMode access_mode,
FS_OpenMode open_mode);
/**
* Closes the file.
* @param stream
* @return true
* @return false
*/
bool buffered_file_stream_close(Stream* stream);
/**
* Retrieves the error id from the file object
* @param stream pointer to stream object.
* @return FS_Error error id
*/
FS_Error buffered_file_stream_get_error(Stream* stream);
#ifdef __cplusplus
}
#endif