Home / Function/ send() — astro Function Reference

send() — astro Function Reference

Architecture documentation for the send() function in sirv.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  f1272528_bd1e_a0e1_55bd_cfec8a2d0850["send()"]
  afcb3082_013d_93cb_836e_f55956dc999b["sirv.ts"]
  f1272528_bd1e_a0e1_55bd_cfec8a2d0850 -->|defined in| afcb3082_013d_93cb_836e_f55956dc999b
  style f1272528_bd1e_a0e1_55bd_cfec8a2d0850 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/integrations/partytown/src/sirv.ts lines 96–130

function send(req, res, file, stats, headers) {
	let code = 200,
		tmp,
		opts = {};
	headers = { ...headers };

	for (let key in headers) {
		tmp = res.getHeader(key);
		if (tmp) headers[key] = tmp;
	}

	if ((tmp = res.getHeader('content-type'))) {
		headers['Content-Type'] = tmp;
	}

	if (req.headers.range) {
		code = 206;
		let [x, y] = req.headers.range.replace('bytes=', '').split('-');
		let end = (opts.end = parseInt(y, 10) || stats.size - 1);
		let start = (opts.start = parseInt(x, 10) || 0);

		if (start >= stats.size || end >= stats.size) {
			res.setHeader('Content-Range', `bytes */${stats.size}`);
			res.statusCode = 416;
			return res.end();
		}

		headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
		headers['Content-Length'] = end - start + 1;
		headers['Accept-Ranges'] = 'bytes';
	}

	res.writeHead(code, headers);
	fs.createReadStream(file, opts).pipe(res);
}

Domain

Subdomains

Frequently Asked Questions

What does send() do?
send() is a function in the astro codebase, defined in packages/integrations/partytown/src/sirv.ts.
Where is send() defined?
send() is defined in packages/integrations/partytown/src/sirv.ts at line 96.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free