Skip to content

Commit a7f4bc6

Browse files
authored
Change MultipartFile#file type to BusboyFileStream (#307)
1 parent 22a3666 commit a7f4bc6

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Busboy, BusboyConfig } from "@fastify/busboy";
1+
import { Busboy, BusboyConfig, BusboyFileStream } from "@fastify/busboy";
22
import { FastifyPluginCallback } from "fastify";
33
import { Readable } from 'stream';
44
import { FastifyErrorConstructor } from "fastify-error";
@@ -27,7 +27,7 @@ export type Multipart<T = true> = T extends true ? MultipartFile : MultipartValu
2727

2828
export interface MultipartFile {
2929
toBuffer: () => Promise<Buffer>,
30-
file: Readable,
30+
file: BusboyFileStream,
3131
filepath: string,
3232
fieldname: string,
3333
filename: string,

test/index.test-d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { pipeline, Readable } from 'stream'
66
import * as fs from 'fs'
77
import { expectError, expectType } from 'tsd'
88
import { FastifyErrorConstructor } from "fastify-error"
9-
import { BusboyConfig } from "@fastify/busboy";
9+
import { BusboyConfig, BusboyFileStream } from "@fastify/busboy";
1010

1111
const pump = util.promisify(pipeline)
1212

@@ -56,7 +56,8 @@ const runServer = async () => {
5656
app.post('/', async (req, reply) => {
5757
const data = await req.file()
5858

59-
expectType<Readable>(data.file)
59+
expectType<BusboyFileStream>(data.file)
60+
expectType<boolean>(data.file.truncated)
6061
expectType<MultipartFields>(data.fields)
6162
expectType<string>(data.fieldname)
6263
expectType<string>(data.filename)
@@ -73,7 +74,7 @@ const runServer = async () => {
7374
expectError(req.body.foo.file);
7475
expectType<string>(req.body.foo.value);
7576

76-
expectType<Readable>(req.body.file.file)
77+
expectType<BusboyFileStream>(req.body.file.file)
7778
expectError(req.body.file.value);
7879
reply.send();
7980
})
@@ -83,7 +84,7 @@ const runServer = async () => {
8384
reply.send();
8485

8586
// file is a file
86-
expectType<Readable>(req.body.file.file)
87+
expectType<BusboyFileStream>(req.body.file.file)
8788
expectError(req.body.file.value);
8889
})
8990

0 commit comments

Comments
 (0)