Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 2.35 KB

file_splitter_task.md

File metadata and controls

60 lines (47 loc) · 2.35 KB

FileSplitterTask

Splits a long text file into smaller temporary files of at most max_lines lines. Iterates over the produced files until the whole source file has been processed.

Task reference

  • Service: CleverAge\ProcessBundle\Task\File\FileSplitterTask
  • Code: file_splitter (task: file_splitter)
  • Iterable task

Accepted inputs

array: optional, its file_path and max_lines values replace the ones of the task options (e.g. { file_path: ..., max_lines: ... }). The file_path option is still required in the task configuration (the options are resolved before the input is merged): to give the file path as input only, set a placeholder value in the options. Any other input is ignored.

Possible outputs

string: path of a temporary file (created in the system temporary directory, with a random name, a .tmp extension and readable by its owner only) containing the next max_lines lines of the source file (the last file may contain fewer lines).

Options

Code Type Required Default Description
file_path string X Path of the file to split
max_lines int 1000 Maximum number of lines per produced file, must be greater than 0

Examples

# Task configuration level
entry:
  task: file_splitter
  options:
    file_path: '%kernel.project_dir%/var/data/json_stream_reader.json'
    max_lines: 100
  outputs: [read_chunk]
read_chunk:
  task: input_line_reader

Notes

  • Values given as input (file_path, max_lines) are validated like the options; other input keys are ignored.
  • Every line of the source file is kept, in order, including empty lines. Line content is preserved, but each line break (\n or \r\n) is written as PHP_EOL, and a missing line break on the last line is added.
  • An empty source file produces no output (the task is skipped).
  • Temporary files are not deleted by the task, use FileRemoverTask if needed.
  • For CSV files, prefer CsvSplitterTask which keeps the headers in each produced file.