@@ -2,31 +2,56 @@ import type { H3Event } from 'h3'
22import type { RenderResponse } from './helper'
33import { compress , getAnyCompression } from './helper'
44
5+ /**
6+ * Compresses the response with [zlib.gzip]{@link https://www.w3schools.com/nodejs/ref_zlib.asp}
7+ * @param { H3Event } event - A H3 event object.
8+ * @param { RenderResponse } response - A response object with body parameter.
9+ * @returns { Promise<void> }
10+ */
511export async function useGZipCompression (
612 event : H3Event ,
713 response : Partial < RenderResponse > ,
8- ) {
14+ ) : Promise < void > {
915 await compress ( event , response , 'gzip' )
1016}
1117
18+ /**
19+ * Compresses the response with [zlib.deflate]{@link https://www.w3schools.com/nodejs/ref_zlib.asp}
20+ * @param { H3Event } event - A H3 event object.
21+ * @param { RenderResponse } response - A response object with body parameter.
22+ * @returns { Promise<void> }
23+ */
1224export async function useDeflateCompression (
1325 event : H3Event ,
1426 response : Partial < RenderResponse > ,
15- ) {
27+ ) : Promise < void > {
1628 await compress ( event , response , 'deflate' )
1729}
1830
31+ /**
32+ * Compresses the response with [zlib.brotliCompress]{@link https://www.w3schools.com/nodejs/ref_zlib.asp}
33+ * @param { H3Event } event - A H3 event object.
34+ * @param { RenderResponse } response - A response object with body parameter.
35+ * @returns { Promise<void> }
36+ */
1937export async function useBrotliCompression (
2038 event : H3Event ,
2139 response : Partial < RenderResponse > ,
22- ) {
40+ ) : Promise < void > {
2341 await compress ( event , response , 'br' )
2442}
2543
44+ /**
45+ * Compresses the response with [Zlib]{@link https://www.w3schools.com/nodejs/ref_zlib.asp}
46+ * by 'Accept-Encoding' header. Best is used first.
47+ * @param { H3Event } event - A H3 event object.
48+ * @param { RenderResponse } response - A response object with body parameter.
49+ * @returns { Promise<void> }
50+ */
2651export async function useCompression (
2752 event : H3Event ,
2853 response : Partial < RenderResponse > ,
29- ) {
54+ ) : Promise < void > {
3055 const compression = getAnyCompression ( event )
3156 if ( compression )
3257 await compress ( event , response , compression )
0 commit comments