CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tmp-promise

The tmp package with promises support and disposers.

93

1.78x
Overview
Eval results
Files

task.mdevals/scenario-5/

Batch File Processor with Automatic Cleanup

Build a batch file processor that processes multiple input files, creates temporary files for intermediate results, and ensures all temporary resources are cleaned up even if the process crashes or is interrupted.

Requirements

Your task is to create a Node.js application that:

  1. Reads multiple input files from a specified directory
  2. Processes each file (e.g., converts text to uppercase)
  3. Stores intermediate results in temporary files
  4. Combines all results into a single output file
  5. Ensures all temporary files are cleaned up automatically, even if:
    • The process exits normally
    • The process is interrupted (Ctrl+C)
    • An uncaught exception occurs during processing

Implementation Details

Create a module that exports a processBatch function with the following behavior:

  • Accepts two parameters: inputDir (directory containing input files) and outputPath (path for final output)
  • Reads all .txt files from the input directory
  • For each input file, creates a temporary file to store the processed content
  • Processes the content (converts to uppercase)
  • Writes processed content to the temporary file
  • After all files are processed, combines all temporary files into the final output file
  • The application must be configured to automatically clean up temporary files on exit

API

/**
 * Processes batch files from input directory and combines results.
 *
 * @param {string} inputDir - Directory containing input .txt files
 * @param {string} outputPath - Path for the combined output file
 * @returns {Promise<void>}
 */
async function processBatch(inputDir, outputPath) {
  // Implementation
}

module.exports = { processBatch };

Implementation

@generates

Capabilities

Basic batch processing

  • Given an input directory with two files "a.txt" (content: "hello") and "b.txt" (content: "world"), the output file contains "HELLO\nWORLD" @test
  • Given an input directory with a single file "test.txt" (content: "test content"), the output file contains "TEST CONTENT" @test

Automatic cleanup

  • When processing files, temporary files are created and then cleaned up after the output is generated @test

Dependencies { .dependencies }

tmp-promise { .dependency }

Provides temporary file creation and automatic cleanup functionality.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-tmp-promise

tile.json