2

I am using Angular 5 on the client-side. I have some large text content that I need to upload to my server using my API. I am trying to pass the Content-Encoding: gzip header and send compressed contents to the server from Angular 5.

I tried researching few gzip libraries like pako, zlib, etc and none of the play well (missing types) with TypeScript. Are there any good gzip libraries that I can use with TypeScript?

Thanks

Narayanan
  • 105
  • 2
  • 7

1 Answers1

0

For using pako do this list of actions:

  1. Install pako -
npm install pako

Or

bower install pako

  1. Add this line in your ts file

import { inflate, deflate, gzip, ungzip } from 'pako';

And where you want to compress your array:

const options = {
  level: 9,
  name: 'hello-world.txt',
  timestamp: parseInt(Date.now() / 1000, 10)
};
const binaryString = gzip(JSON.stringify(options), { to: 'string' });
console.log(binaryString.length);

//
// Here you can do base64 encode, make xhr requests and so on.
//
const restored = JSON.parse(ungzip(binaryString, { to: 'string' }));
console.log(restored);

Site of pako:

https://nodeca.github.io/pako/

Important information for sending gzip to server:

Compress Outgoing Requests in Angular 2+

Good luck!

Zvi Redler
  • 1,708
  • 1
  • 18
  • 29