為了控制記憶體的使用量,LiteDB 限制資料的存放量為 1 MB,1 MB 對於一般的資料而言是已經足夠了,但是對於二進制檔案來說就不怎麼足夠,所以 LiteDB 提供 FileStorage 用以存放二進制檔案。
FileStorage 支援以下方法:
Method | Description |
---|---|
Upload | Send file or stream to database. Can be used with file or Stream. If file already exists, file content is overwritten. |
Download | Get your file from database and copy to Stream parameter |
Delete | Delete a file reference and all data chunks |
Find | Find one or many files in _files collection. Returns LiteFileInfo class, that can be download data after. |
SetMetadata | pdate stored file metadata. This method doesn’t change the value of the stored file. It updates the value of _files.metadata. |
OpenRead | Find file by _id and returns a LiteFileStream to read file content as stream |
像是要塞入二進制的檔案,可以使用 FileStorage.Upload 方法,調用時帶入識別檔案用的 ID,以及檔案的位置。
1 | … |
1 | using System; |
要開啟二進制檔案,可以使用 FileStorage.OpenRead 方法,調用時帶入識別檔案用的 ID。
1 | … |
1 | using System; |
要將 LiteDB 內的二進制檔案寫回硬碟,可以使用 FileStorage.Download 方法,調用時帶入識別檔案的 ID,及目的檔案串流。
1 | … |
1 | using System; |