Skip to main content

Read

Reads a file from the local filesystem with line numbers and encoding support.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.

Inputs

  • File Path - string - Absolute path to the file to read (required).
  • Line Offset - int - Starting line number to read from (1-based, optional).
  • Line Limit - int - Maximum number of lines to read (optional, default: 2000).

Options

  • Encoding - Character encoding of the file. Options: Auto Detect, UTF-8, UTF-16, Windows-1252, ISO-8859-1 (default: Auto Detect).
  • Max Line Length - Maximum characters per line. Longer lines will be truncated (default: 2000).

Outputs

  • Content - string - File contents with line numbers in cat -n format.
  • Line Count - int - Total number of lines read.
  • Is Binary - bool - Whether the file appears to be binary.
  • Detected Encoding - string - The detected or used character encoding.
  • File Info - object - File metadata including size, modified time, and permissions.

How It Works

The Read node reads files from the filesystem and returns formatted content with line numbers. When executed, the node:

  1. Validates the file path is absolute
  2. Checks if the file exists and is accessible
  3. Detects if the file is binary or text
  4. For binary files: Returns base64-encoded content (limited to 10MB)
  5. For text files:
    • Detects or uses the specified encoding
    • Reads lines with optional offset and limit
    • Formats each line with line number (6-digit, tab-separated)
    • Truncates lines exceeding max length
  6. Returns comprehensive file metadata

Requirements

  • Valid absolute file path
  • Read permissions on the file
  • For text files: Valid encoding (auto-detected or specified)

Error Handling

The node will return specific errors in the following cases:

  • Missing file path - "File path is required"
  • Relative path - "File path must be absolute"
  • File not found - "File not found: {{path}}"
  • Access denied - "Cannot access file: {{error}}"
  • Directory instead of file - "Path is a directory, not a file"
  • Read errors - "Error reading file: {{error}}"

Usage Examples

Basic File Reading

Read the entire file:

File Path: /home/user/documents/data.txt

Read Specific Lines

Read 100 lines starting from line 50:

File Path: /home/user/logs/application.log
Line Offset: 50
Line Limit: 100

Read with Specific Encoding

Read a Windows-encoded file:

File Path: /home/user/windows_file.txt
Encoding: Windows-1252

Binary File Handling

Read an image file (returns base64):

File Path: /home/user/images/photo.jpg

Output: Base64-encoded content with file size information

Usage Notes

  • The node automatically detects file encoding by checking for BOM (Byte Order Mark)
  • Binary detection checks for null bytes and non-printable characters
  • Line numbers are formatted as 6-digit numbers followed by a tab
  • Lines longer than Max Line Length are truncated with "..." appended
  • Binary files larger than 10MB are truncated with a size note
  • The default limit of 2000 lines prevents memory issues with large files
  • Output format is compatible with standard cat -n format
  • File Info includes: size (bytes), modTime (ISO 8601), permissions (Unix format), name

Common Use Cases

Code Review

Read source code files with line numbers for easy reference.

Log Analysis

Read log files with offset and limit to analyze specific time ranges.

Configuration Validation

Read configuration files to verify settings.

Binary File Detection

Check if files are binary before processing.

Encoding Detection

Auto-detect file encoding for international text files.