Class: FileResult
A file: a path, a buffer or a stream. The HTTP adapters send it with its options; the CLI adapter writes its content to stdout. Build it with Result.file().
Example
typescript
import {Readable} from 'node:stream'
import {Controller, Result, type FileResult} from 'lakutata/com/entrypoint'
import {GET} from 'lakutata/decorator/ctrl'
class ReportController extends Controller {
//A file on disk, downloaded as report.pdf
@GET('/report')
public async report(): Promise<FileResult> {
return Result.file('./reports/latest.pdf', {filename: 'report.pdf', etag: 'v1'})
}
//A stream, with its content type
@GET('/export')
public async export(): Promise<FileResult> {
return Result.file(Readable.from(['id,name\n', '1,Ada\n']), {contentType: 'text/csv'})
}
}Extends
Constructors
Constructor
new FileResult(
source,options?):FileResult
Create a file result.
Parameters
source
string | Buffer<ArrayBufferLike> | Readable
The file's path (resolved from the working directory), its content, or a stream of its content.
options?
How the file is sent.
Returns
FileResult
Overrides
Properties
options
readonlyoptions:FileResultOptions
source
readonlysource:string|Buffer<ArrayBufferLike> |Readable
Accessors
data
Get Signature
get data():
unknown
The file's source.
Returns
unknown