Sample code for 30+ languages & platforms
React Native

Download a Zip from a URL and OpenBd. (No .zip file is created)

See more Zip Examples

Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.

Chilkat React Native Downloads

React Native
import { BinData, Http, StringBuilder, Zip, ZipEntry } from '@chilkat/react-native'

async function chilkatExample() {
  let success = false;

  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new Http();

  const bd = new BinData();

  // This URL is valid and can be tested...
  try {
    await http.quickGetBdAsync('https://chilkatdownload.com/example_data/hamlet.zip', bd);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const zip = new Zip();

  // Open the zip from the bytes contained in bd.
  try {
    zip.openBd(bd);
  } catch {
    console.log(zip.lastErrorText);
    return;
  }

  // Get the entry for the file we want..
  const entry = new ZipEntry();
  success = zip.entryOf('hamlet.xml', entry);
  if (!success) {
    console.log(zip.lastErrorText);
    return;
  }

  // Convert all line endings to CRLF (if needed)
  const lineEndingBehavior = 2;
  let xmlStr: string;
  try {
    xmlStr = await entry.unzipToStringAsync(lineEndingBehavior, 'utf-8');
  } catch {
    console.log(entry.lastErrorText);
    return;
  }

  // The XML in this case is about 274K, so let's just examine the last 20 lines...
  const sb = new StringBuilder();
  sb.append(xmlStr);

  console.log(sb.lastNLines(20, true));
}