React Native Requires Chilkat v11.0.0+
React Native
Create a Zip Entirely in Memory
See more Zip Examples
Demonstrates how to create a .zip from in-memory byte data and strings, and to write the .zip to an in-memory image.Chilkat React Native Downloads
import { BinData, Crypt2, FileAccess, Zip } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const crypt = new Crypt2();
const zip = new Zip();
try {
zip.newZip('test.zip');
} catch {
console.log(zip.lastErrorText);
return;
}
// Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
const bd = new BinData();
bd.appendEncoded('000102030405060708090A0B0C0D0E0F', 'hex');
zip.addBd('binaryData.dat', bd);
// Add the string "Hello World!" to the .zip
zip.addString('helloWorld.txt', 'Hello World!', 'utf-8');
const zipFileInMemory = await zip.writeToMemoryAsync();
// We could save these files to a file, and it is a valid .zip
const fac = new FileAccess();
try {
fac.writeEntireFile('test.zip', zipFileInMemory);
} catch {
console.log(fac.lastErrorText);
return;
}
console.log('Zip Created!');
}