Skip to content

Commit

Permalink
feat(hono/context): add buffer returns
Browse files Browse the repository at this point in the history
  • Loading branch information
askorupskyy committed Jan 8, 2025
1 parent 2ead4d8 commit 4ce76f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions runtime-tests/node/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,20 @@ describe('compress', async () => {
expect(res.text).toBe(cssContent)
})
})

describe('Buffers', () => {
const buffer = Buffer.from('hello')
buffer.write('Hello')

const app = new Hono().get('/', async (c) => {
return c.body(buffer)
})

const server = createAdaptorServer(app)

it('should allow returning buffers', async () => {
const res = await request(server).get('/')
expect(res.status).toBe(200)
expect(res.text).toBe('Hello')
})
})
6 changes: 4 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Buffer } from 'node:buffer'

import { HonoRequest } from './request'
import type { Result } from './router'
import type {
Expand Down Expand Up @@ -27,9 +29,9 @@ type HeaderRecord =
| Record<string, string | string[]>

/**
* Data type can be a string, ArrayBuffer, or ReadableStream.
* Data type can be a string, ArrayBuffer, Buffer, or ReadableStream.
*/
export type Data = string | ArrayBuffer | ReadableStream
export type Data = string | ArrayBuffer | ReadableStream | Buffer

/**
* Interface for the execution context in a web worker or similar environment.
Expand Down

0 comments on commit 4ce76f9

Please sign in to comment.