HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/rest/node_modules/machinepack-fs/machines/read-sync.js
module.exports = {


  friendlyName: 'Read file (sync)',


  description: 'Read a file on disk as a string.',


  extendedDescription: 'Assumes file contents are encoded using utf8. This machine should **NEVER** be used in request handling code!',


  sync: true,


  cacheable: true,


  inputs: {

    source: {
      description: 'Absolute path to the source file (if relative path is provided, will resolve path from current working directory)',
      example: '/Users/mikermcneil/.tmp/foo',
      required: true
    }

  },


  exits: {

    doesNotExist: {
      description: 'No file exists at the provided `source` path'
    },

    success: {
      example: 'stuff in a file!',
      description: 'Returns the contents of the file at `source` path'
    }

  },


  fn: function (inputs, exits) {
    var path = require('path');
    var fs = require('fs');

    // In case we ended up here w/ a relative path,
    // resolve it using the process's CWD
    inputs.source = path.resolve(inputs.source);

    var contents;
    try {
      contents = fs.readFileSync(inputs.source, 'utf8');
      // It worked!
      return exits.success(contents);
    }
    catch (e) {
      if (e.code === 'ENOENT') {
        return exits.doesNotExist();
      }
      // Some unrecognized error
      return exits.error(err);
    }
  }

};