The Node Fielded Text library extends several classes in @pbkware/fielded-text-web so that they support reading and writing to files with the Node runtime.
The following constructors are added to the corresponding classes which enable Fielded Text data to be read or written to/from files.
new FtNodeFileReader(
filePath: PathLike,
metaOrEncoding?: BufferEncoding | FtMeta,
encoding?: BufferEncoding,
immediatelyReadHeader?: boolean,
): FtNodeFileReader
new FtNodeFileWriter(
filePath: PathLike,
meta: FtMeta,
encoding?: BufferEncoding,
settings?: FtWriterSettings,
): FtNodeFileWriter
When reading data, it is necessary to have the Meta associated with the data. This can be provided to the function in 2 ways:
metaOrEncoding parameter)metaOrEncoding parameter specifies the encoding of the file specified in the declaration. If this parameter is not included (or undefined), the encoding defaults to utf-8.For both reading and writing, the 3rd parameter (encoding) specifies the encoding of the specified file data (filePath parameter). If this value is not included or undefined, the encoding defaults to utf-8.
The following methods are added to FtMetaSerialization & FtXmlMetaSerialization which enable reading and writing of Meta to/from files.
serializeToFile(
meta: FtMeta,
filePath: PathOrFileDescriptor,
options?: FtMetaSerializerOptions,
encoding?: BufferEncoding,
format?: FtMetaSerializationFormat, // not included in FtNodeXmlMetaSerialization as always `XML`
): void
deserializeFromFile(
filePath: PathOrFileDescriptor,
warnings?: string[],
encoding?: BufferEncoding,
format?: FtMetaSerializationFormat, // not included in FtNodeXmlMetaSerialization as always `XML`
): FtMeta
The encoding parameter specifies the encoding of the data in the file. If not present or undefined, it defaults to utf-8.