Function ic_sqlite_features::backup::stream_db_backup
source · pub fn stream_db_backup(conn: &mut Connection) -> Result<impl Read, Error>
Expand description
Streams a backup of the database as uncompressed data.
This function retrieves all pages of the database and accumulates them into a
Vec<u8>
. It returns the accumulated data wrapped in an io::Cursor
for streaming.
Be aware that this function will try to load the entire database into memory all at once, which may not be feasible for very large databases and could lead to high memory usage or out-of-memory errors. It is particularly useful for cases where you need to stream the database backup without compressing it.
§Returns
Returns an io::Result<impl Read>
where the impl Read
is an io::Cursor
over a
Vec<u8>
containing the uncompressed database data. This allows for streaming the
data as needed.
§Errors
This function returns an io::Error
if:
- The database connection is not properly initialized or locked.
- The transaction cannot be started or committed.
- Page data cannot be read from the virtual file system or written to the buffer.
§Panics
This function may panic if:
- The transaction cannot be started or committed.
- Page data cannot be read or written to the buffer.
§Example
use std::io::Read;
use ic_sqlite_features::stream_db_backup;
let mut backup_stream = stream_db_backup().expect("Failed to create backup stream");
let mut buffer = Vec::new();
backup_stream.read_to_end(&mut buffer).expect("Failed to read backup data");
// Use `buffer` as needed