Skip to main content
File Operations

Streaming Download

DownloadValidateHard

What you will learn

  • Transfer-Encoding: chunked enables incremental reads โ€” verify the client can consume partial data, not require full body
  • Range requests (HTTP 206) let clients resume interrupted downloads โ€” test with byte-range headers, assert 206 + correct slice
  • Server must release file handles on client-disconnect โ€” run a test that cancels mid-stream and asserts the file descriptor count doesn't grow

Description

Handle large file downloads with streaming. Monitor progress and handle backpressure.

Test Scenario

// Node.js: Streaming download with progress
const https = require('https');
const fs = require('fs');

const file = fs.createWriteStream('large_file.bin');
let downloaded = 0;

https.get('http://localhost:3003/api/v1/files/download?format=large&size=5', (res) => {
  const totalSize = parseInt(res.headers['content-length']);

  res.on('data', (chunk) => {
    downloaded += chunk.length;
    const progress = ((downloaded / totalSize) * 100).toFixed(1);
    console.log(`Progress: ${progress}%`);
  });

  res.pipe(file);

  file.on('finish', () => {
    file.close();
    console.log('Download complete');
  });
});
Endpoint/api/v1/files/download?format=large&size=5

Testing Tips

  • โ€ขUse streaming to handle large files
  • โ€ขMonitor Content-Length for progress
  • โ€ขHandle network interruptions gracefully
  • โ€ขConsider timeout settings for slow connections
// Playwright API Testing - File Operations
import { test, expect } from '@playwright/test';
test('File download', async ({ request }) => {
const response = await request.get('/api/files/download/report.pdf');
expect(response.ok()).toBeTruthy();
expect(response.headers()['content-type']).toContain('application/pdf');
const buffer = await response.body();
expect(buffer.length).toBeGreaterThan(0);
});

Challenge ID: streaming-download

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/files/download?format=large&size=5

Press Enter to send