Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  var success = false;

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

  final http = CkHttp();

  final bd = CkBinData();

  // This URL is valid and can be tested...
  try {
    http.quickGetBd('https://chilkatdownload.com/example_data/hamlet.zip', bd);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final zip = CkZip();

  // Open the zip from the bytes contained in bd.
  try {
    zip.openBd(bd);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Get the entry for the file we want..
  final entry = CkZipEntry();
  success = zip.entryOf('hamlet.xml', entry);
  if (!success) {
    print(zip.lastErrorText);
    return;
  }

  // Convert all line endings to CRLF (if needed)
  final lineEndingBehavior = 2;
  final String xmlStr;
  try {
    xmlStr = entry.unzipToString(lineEndingBehavior, 'utf-8');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

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

  print(sb.lastNLines(20, true));
}