Reputation: 115
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
Upvotes: 3
Views: 2162
Reputation: 1
With Angular / Typescript, you also have to run the npm i --save-dev @types/pako command to use Pako.
npm install pako
npm i --save-dev @types/pako
Upvotes: 0
Reputation: 1768
For using pako do this list of actions:
npm install pako
Or
bower install pako
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!
Upvotes: 1