All files / rusted-chromium/store exportStore.ts

100% Statements 14/14
100% Branches 6/6
100% Functions 1/1
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 232x 2x   2x 2x   2x 2x   2x 5x 1x     5x 5x 2x     3x 3x    
import { createReadStream } from 'node:fs'
import { join } from 'node:path'
 
import { LOCAL_STORE_FILE } from '../commons/constants'
import { NoLocalstoreError } from '../errors'
import type { IExportConfig } from '../interfaces/interfaces'
import { DebugMode, logger } from '../log/logger'
import { existsAndIsFile } from '../utils/file.utils'
 
export async function exportStore(config: IExportConfig, stdio: NodeJS.WriteStream): Promise<void> {
    if(config.debug) {
        logger.setDebugMode(DebugMode.DEBUG)
    }
 
    const filePath = config.path ?? join(__dirname, '..', LOCAL_STORE_FILE)
    if (!(await existsAndIsFile(filePath))) {
        throw new NoLocalstoreError(config.path)
    }
 
    const reader = createReadStream(filePath)
    reader.pipe(stdio)
}