# All files / src/file-readers backend-file-reader.ts

66.67% Statements 8/12
50% Branches 3/6
50% Functions 2/4
66.67% Lines 8/12

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
    23
    24
    25
    26
    27
    28
    29
    30
    311x

    1x

    1x

    14730x
    20x

    14710x
    14710x

    14710x

     import * as fs from 'fs';
    import { IResourceRead } from '../interfaces';
    import * as path from 'path';

    export class BackendFileReader implements IResourceRead {
      public recordTransformer: Function;

      setRecordTransformer(recordTransformer) {
        this.recordTransformer = recordTransformer;
      }

      checkFile(filePath: string) {
        return fs.existsSync(filePath) ? 200 : 404;
      }

      readText(filePath, onFileRead, options: object) {
        if (!fs.existsSync(filePath)) {
          return onFileRead('No such file: ' + filePath);
        }

        fs.readFile(path.resolve(filePath), 'utf-8', (err, content) => {
          Iif (err) {
            onFileRead(err);
            return;
          }

          onFileRead(null, content.toString());
        });
      }
    }