image-fixtures.ts 1.3 KB

123456789101112131415161718192021
  1. // Synthetic format headers for parser tests; no user images or captured requests.
  2. function jpeg(width: number, height: number, exif = false): string {
  3. const frame = Buffer.from([0xff, 0xc0, 0, 17, 8, height >> 8, height & 255, width >> 8, width & 255, 3, 1, 0x11, 0, 2, 0x11, 0, 3, 0x11, 0]);
  4. const prefix = exif ? Buffer.from([0xff, 0xe1, 0, 8, 69, 120, 105, 102, 0, 0]) : Buffer.alloc(0);
  5. return Buffer.concat([Buffer.from([0xff, 0xd8]), prefix, frame, Buffer.from([0xff, 0xd9])]).toString('base64');
  6. }
  7. const png = Buffer.alloc(33);
  8. Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]).copy(png);
  9. png.writeUInt32BE(13, 8);
  10. png.write('IHDR', 12);
  11. png.writeUInt32BE(40, 16);
  12. png.writeUInt32BE(24, 20);
  13. export const NORMAL_40X24_PNG = png.toString('base64');
  14. export const NORMAL_64X48_JPEG = jpeg(64, 48);
  15. export const THIN_432X2_JPEG = jpeg(432, 2);
  16. export const BOUNDARY_100X7_JPEG = jpeg(100, 7);
  17. export const BOUNDARY_100X8_JPEG = jpeg(100, 8);
  18. export const EXIF_80X60_JPEG = jpeg(80, 60, true);
  19. export const CORRUPT_TRUNCATED_JPEG = Buffer.from([0xff, 0xd8, 0xff, 0xc0, 0, 17, 8]).toString('base64');
  20. export const MALFORMED_SHORT_SOF_JPEG = Buffer.from([0xff, 0xd8, 0xff, 0xc0, 0, 3, 8, 0, 5, 0, 7, 3]).toString('base64');
  21. export const UNSUPPORTED_50X50_WEBP = Buffer.from('RIFF0000WEBPVP8 synthetic').toString('base64');