FileStorage
import { FileStorage } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods.
XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or reading data to/from a file.
Constructors and members
static new
The constructors.
The full constructor opens the file. Alternatively you can use the default constructor and then
call FileStorage::open.
new(filename: EmbindString, flags: number, encoding: EmbindString): FileStorage;3 available overloads
new(): FileStorage;new(filename: EmbindString, flags: number): FileStorage;new(filename: EmbindString, flags: number, encoding: EmbindString): FileStorage;filenameName of the file to open or the text string to read the data from. Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. You can also specify a compression level from 0 to 9 by appending it to the extension (e.g. ".gz0" for no compression, ".gz9" for high compression). The last digit will be truncated internally to write/read. (e.g. If "a.xml.gz9" is specified, "a.xml.gz" is used for the actual file name.) If both FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to FileStorage::BASE64 flag.
flagsMode of operation. One of FileStorage::Mode
encodingEncoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.()
The FileStorage result.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
open
Opens a file.
See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release
before opening the file.
open(filename: EmbindString, flags: number, encoding: EmbindString): boolean;2 available overloads
open(filename: EmbindString, flags: number): boolean;open(filename: EmbindString, flags: number, encoding: EmbindString): boolean;filenameName of the file to open or the text string to read the data from. Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. You can also specify a compression level from 0 to 9 by appending it to the extension (e.g. ".gz0" for no compression, ".gz9" for high compression). The last digit will be truncated internally to write/read. (e.g. If "a.xml.gz9" is specified, "a.xml.gz" is used for the actual file name.) If both FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to FileStorage::BASE64 flag.
flagsMode of operation. One of FileStorage::Mode
encodingEncoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.
The boolean result.
isOpened
Checks whether the file is opened.
isOpened(): boolean;true if the object is associated with the current file and false otherwise. It is a good practice to call this method after you tried to open a file.
release
Closes the file and releases all the memory buffers.
Call this method after all I/O operations with the storage are finished.
release(): void;releaseAndGetString
Closes the file and releases all the memory buffers.
Call this method after all I/O operations with the storage are finished. If the storage was
opened for writing data and FileStorage::WRITE was specified
releaseAndGetString(): string;The string result.
write
Simplified writing API to use with bindings.
write(name: EmbindString, val: number): void;nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.
write1
Simplified writing API to use with bindings.
write1(name: EmbindString, val: boolean): void;nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.
write2
Simplified writing API to use with bindings.
write2(name: EmbindString, val: bigint): void;nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.
write3
Simplified writing API to use with bindings.
write3(name: EmbindString, val: number): void;nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.
write4
Simplified writing API to use with bindings.
write4(name: EmbindString, val: EmbindString): void;nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.
write5
Simplified writing API to use with bindings.
write5(name: EmbindString, val: Mat): void;nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.
write6
Simplified writing API to use with bindings.
write6(name: EmbindString, val: StringVector): void;nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.
writeComment
Writes a comment.
The function writes a comment into file storage. The comments are skipped when the storage is read.
writeComment(comment: EmbindString, append: boolean): void;2 available overloads
writeComment(comment: EmbindString): void;writeComment(comment: EmbindString, append: boolean): void;commentThe written comment, single-line or multi-line
appendIf true, the function tries to put the comment at the end of current line. Else if the comment is multi-line, or if it does not fit at the end of the current line, the comment starts a new line.
startWriteStruct
Starts to write a nested structure (sequence or a mapping).
startWriteStruct(name: EmbindString, flags: number, typeName: EmbindString): void;2 available overloads
startWriteStruct(name: EmbindString, flags: number): void;startWriteStruct(name: EmbindString, flags: number, typeName: EmbindString): void;namename of the structure. When writing to sequences (a.k.a. "arrays"), pass an empty string.
flagstype of the structure (FileNode::MAP or FileNode::SEQ (both with optional FileNode::FLOW)).
typeNameoptional name of the type you store. The effect of setting this depends on the storage format. I.e. if the format has a specification for storing type information, this parameter is used.
endWriteStruct
Finishes writing nested structure (should pair startWriteStruct())
endWriteStruct(): void;getFormat
Returns the current format.
getFormat(): number;The current format, see FileStorage::Mode
getFirstTopLevelNode
Returns the first element of the top-level mapping.
getFirstTopLevelNode(): FileNode;The first element of the top-level mapping.
root
Returns the top-level mapping
root(streamidx: number): FileNode;streamidxZero-based index of the stream. In most cases there is only one stream in the file. However, YAML supports multiple streams and so there can be several.
The top-level mapping.
getNode
Returns the specified element of the top-level mapping.
getNode(nodename: EmbindString): FileNode;nodenameName of the file node.
Node with the given name.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.