@obsidize/rotating-file-stream
v1.2.3
Published
A rotating file stream based on the cordova File plugin API
Downloads
17
Maintainers
Readme
@obsidize/rotating-file-stream
Simple wrapper for streaming data to files on mobile devices in hybrid apps.
If you're using this for log capture on a cordova / capacitor app, consider using cordova-plugin-secure-logger instead.
If you need a pure NodeJS implementation, use rotating-file-stream instead.
Installation
- npm:
npm install --save @obsidize/rotating-file-stream
API
Source documentation can be found here
Usage
- Create A RotationFileStream instance:
import { RotatingFileStream, CordovaFileEntryApi, CapacitorFileEntryApi } from '@obsidize/rotating-file-stream';
const fileStream = new RotatingFileStream({
maxFileSize: 2e6, // 2MB
files: CordovaFileEntryApi.createCacheRotationFiles(
cdvFile, // @awesome-cordova-plugins/file reference
'logs',
['debug-a.log', 'debug-b.log']
)
});
// Or if you want to use @capacitor/filesystem
const fileStream = new RotatingFileStream({
maxFileSize: 2e6, // 2MB
files: CapacitorFileEntryApi.createCacheRotationFiles(
Filesystem, // @capacitor/filesystem reference
'logs',
['debug-a.log', 'debug-b.log']
)
});
- Write to the stream:
const buffer = new ArrayBuffer(42);
fileStream.write(buffer).then(...);
- Read data back later on:
const entries = await fileStream.refreshAllEntries();
for (const entry of entries) {
// read the entry data, or get its URL and do something with it
}