Skip to content

5.2.0

Compare
Choose a tag to compare
@octet-stream octet-stream released this 24 May 15:50

Add

  • AsyncIterable objects support as the source in parse function. In this case you must provide HTTP headers through options argument. Because of that, you can process multipart/form-data bodies from different sources, even from Response:
import {Response, FormData} from "node-fetch" // Has FormData support from v3
import {parse} from "then-bosboy"
const form = new FormData()

form.set("greeting", "Hello, World!")
form.set("file", new File(["On Soviet Moon landscape see binoculars through YOU"], "file.txt"))

const response = new Respone(form)
// then-busboy will parse the input and return its own Body instance from which you can create a complete object by calling .json() method or a FormData using .formData() method.
// The difference with Response.formData() is that then-busboy will save all files to file system and create a *reference* to each of them,
// while Response (currently) will dump them into RAM, which can be less efficient in some scenarious
const body = await parse(response.body, {
  headers: {
    "content-type": response.headers.get("content-type")
  }
})

body.json() // -> {greeting: string, file: BodyFile}
body.formData() // -> FormData

Update

  • Busboy is updated to version 1.x;
  • Improvements for documentation;
  • Body.json() method takes type parameter that will reflect the type returned by this method (TS only)

All changes: v5.1.3...v5.2.0