Modules@robinpath/stream
stream

@robinpath/stream

0.1.1Node.jsPublic

Stream processing for large files: read, write, transform, filter, split, concat, hash without loading into memory

Stream

Stream processing for large files: read, write, transform, filter, split, concat, hash without loading into memory

Package: @robinpath/stream | Category: Infrastructure | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the stream module when you need to:

  • Read entire file content -- Use stream.readFile to perform this operation
  • Write data to file -- Use stream.writeFile to perform this operation
  • Stream-copy a file -- Use stream.copyFile to perform this operation
  • Read file line by line into array -- Use stream.lines to perform this operation
  • Transform file line by line -- Use stream.transform to perform this operation

Quick Reference

FunctionDescriptionReturns
readFileRead entire file contentFile content
writeFileWrite data to file{path, size}
copyFileStream-copy a file{src, dest, size}
linesRead file line by line into arrayArray of lines
transformTransform file line by line{inputPath, outputPath, linesProcessed}
filterFilter file lines by regex pattern{totalLines, matchedLines}
concatConcatenate multiple files{outputPath, filesConcatenated, size}
splitSplit file into chunks{outputFiles, totalLines, chunks}
countCount lines in fileLine count
headRead first N linesFirst N lines
tailRead last N linesLast N lines
pipeDownload URL to file via stream{path, size}
hashStream-hash a fileHex hash string

Functions

readFile

Read entire file content

Module: stream | Returns: string -- File content

stream.readFile "./data.txt"
ParameterTypeRequiredDescription
filePathstringYesFile path
optionsobjectNo{encoding}

writeFile

Write data to file

Module: stream | Returns: object -- {path, size}

stream.writeFile "./out.txt" "hello"
ParameterTypeRequiredDescription
filePathstringYesFile path
datastringYesContent to write

copyFile

Stream-copy a file

Module: stream | Returns: object -- {src, dest, size}

stream.copyFile "./a.txt" "./b.txt"
ParameterTypeRequiredDescription
srcstringYesSource path
deststringYesDestination path

lines

Read file line by line into array

Module: stream | Returns: array -- Array of lines

stream.lines "./data.csv"
ParameterTypeRequiredDescription
filePathstringYesFile path

transform

Transform file line by line

Module: stream | Returns: object -- {inputPath, outputPath, linesProcessed}

stream.transform "./in.txt" "./out.txt" "uppercase"
ParameterTypeRequiredDescription
inputPathstringYesInput file
outputPathstringYesOutput file
typestringYesuppercase
argsobjectNo{prefix, suffix, search, replace}

filter

Filter file lines by regex pattern

Module: stream | Returns: object -- {totalLines, matchedLines}

stream.filter "./log.txt" "./errors.txt" "ERROR"
ParameterTypeRequiredDescription
inputPathstringYesInput file
outputPathstringYesOutput file
patternstringYesRegex pattern

concat

Concatenate multiple files

Module: stream | Returns: object -- {outputPath, filesConcatenated, size}

stream.concat ["a.txt", "b.txt"] "merged.txt"
ParameterTypeRequiredDescription
inputPathsarrayYesArray of file paths
outputPathstringYesOutput file

split

Split file into chunks

Module: stream | Returns: object -- {outputFiles, totalLines, chunks}

stream.split "./big.csv" "./chunks" 1000
ParameterTypeRequiredDescription
inputPathstringYesInput file
outputDirstringYesOutput directory
linesPerChunknumberNoLines per chunk

count

Count lines in file

Module: stream | Returns: number -- Line count

stream.count "./data.txt"
ParameterTypeRequiredDescription
filePathstringYesFile path

head

Read first N lines

Module: stream | Returns: string -- First N lines

stream.head "./data.txt" 20
ParameterTypeRequiredDescription
filePathstringYesFile path
nnumberNoNumber of lines (default 10)

tail

Read last N lines

Module: stream | Returns: string -- Last N lines

stream.tail "./log.txt" 50
ParameterTypeRequiredDescription
filePathstringYesFile path
nnumberNoNumber of lines (default 10)

pipe

Download URL to file via stream

Module: stream | Returns: object -- {path, size}

stream.pipe "https://example.com/file.zip" "./file.zip"
ParameterTypeRequiredDescription
urlstringYesURL to download
outputPathstringYesOutput file path
optionsobjectNo{headers}

hash

Stream-hash a file

Module: stream | Returns: string -- Hex hash string

stream.hash "./data.bin" "sha256"
ParameterTypeRequiredDescription
filePathstringYesFile path
algorithmstringNoHash algorithm (default sha256)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
HTTP ${response.status}: ${response.statusText}Check the error message for details
@desc "Read file and validate result"
do
  set $result as stream.readFile "./data.txt"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Stream workflow

Chain multiple stream operations together.

@desc "Read file, write file, and more"
do
  set $r_readFile as stream.readFile "./data.txt"
  set $r_writeFile as stream.writeFile "./out.txt" "hello"
  set $r_copyFile as stream.copyFile "./a.txt" "./b.txt"
  print "All operations complete"
enddo

2. Safe readFile with validation

Check results before proceeding.

@desc "Read file and validate result"
do
  set $result as stream.readFile "./data.txt"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/stream

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.8 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

devops