• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samvera / serverless-iiif / 20437842545

22 Dec 2025 04:28PM UTC coverage: 95.729% (-1.7%) from 97.403%
20437842545

push

github

mbklein
Fix errant node-iiif release version

169 of 182 branches covered (92.86%)

Branch coverage included in aggregate %.

212 of 216 relevant lines covered (98.15%)

25.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.79
/src/streamify.ts
1
import { LambdaEvent, LambdaResponse, LambdaContext } from "./contracts";
2
import {
12✔
3
  ResponseStream,
4
  streamifyResponse as lambdaStreamifyResponse,
5
} from "lambda-stream";
6

7
/* istanbul ignore next */
8
const maybeStream = (
9
  responseStream: ResponseStream,
10
  prelude: LambdaResponse
11
) => {
12
  if (
13
    "from" in responseStream.constructor &&
14
    typeof responseStream.constructor.from === "function"
15
  ) {
16
    responseStream.constructor.from(responseStream, prelude);
17
  } else {
18
    responseStream.setContentType(
19
      "application/vnd.awslambda.http-integration-response"
20
    );
21
    const preludeJson = JSON.stringify(prelude ?? {});
22
    responseStream.write(preludeJson ?? "");
23
    responseStream.write(Buffer.alloc(8));
24
  }
25
};
26

27
const stringify = (
12✔
28
  handler: (
29
    _event: LambdaEvent,
30
    _context: LambdaContext
31
  ) => Promise<LambdaResponse>
32
) => {
33
  return async (event: LambdaEvent, context: LambdaContext) => {
×
34
    const result: LambdaResponse = await handler(event, context);
×
35
    const body = result.body.toString("base64");
×
36
    return { ...result, isBase64Encoded: true, body };
×
37
  };
38
};
39

40
const streamify = (
12✔
41
  handler: (
42
    _event: LambdaEvent,
43
    _context: LambdaContext
44
  ) => Promise<LambdaResponse>
45
) => {
46
  return lambdaStreamifyResponse(
20✔
47
    async (
48
      event: LambdaEvent,
49
      responseStream: ResponseStream,
50
      context: LambdaContext
51
    ) => {
52
      const result: LambdaResponse = (await handler(event, context)) || {};
72!
53
      const body = result.body;
72✔
54
      const prelude = { ...result };
72✔
55
      delete prelude.body;
72✔
56
      maybeStream(responseStream, prelude);
72✔
57
      const chunk =
58
        typeof body === "string" ||
72✔
59
        (body as unknown) instanceof Uint8Array ||
60
        Buffer.isBuffer(body)
61
          ? body
62
          : String(body ?? "");
6✔
63
      responseStream.write(chunk);
72✔
64
      responseStream.end();
72✔
65
    }
66
  );
67
};
68

69
export const streamifyResponse = (
12✔
70
  handler: (
71
    _event: LambdaEvent,
72
    _context: LambdaContext
73
  ) => Promise<LambdaResponse>
74
) => {
75
  if (process.env.STREAMIFY_DISABLED === "true") return stringify(handler);
20!
76
  return streamify(handler);
20✔
77
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc