tar 0.2.0-nullsafety copy "tar: ^0.2.0-nullsafety" to clipboard
tar: ^0.2.0-nullsafety copied to clipboard

outdated

Memory-efficient, streaming implementation of the tar file format

example/main.dart

import 'dart:convert';
import 'dart:io';

import 'package:tar/tar.dart';

Future<void> main() async {
  // Start reading a tar file
  final reader = TarReader(File('reference/gnu.tar').openRead());

  while (await reader.moveNext()) {
    final header = reader.header;
    print('${header.name}: ');

    // Print the output if it's a regular file
    if (header.typeFlag == TypeFlag.reg) {
      print(await reader.contents.transform(utf8.decoder).first);
    }
  }

  // We can write tar files to any stream sink like this:
  final output = File('test.tar').openWrite();

  await Stream<TarEntry>.value(
    TarEntry.data(
      TarHeader(
          name: 'hello_dart.txt',
          mode: int.parse('644', radix: 8),
          userName: 'Dart',
          groupName: 'Dartgroup'),
      utf8.encode('Hello world'),
    ),
  )
      // transform tar entries back to a byte stream
      .transform(tarWriter)
      // and then write that to the file
      .pipe(output);
}
31
likes
0
pub points
90%
popularity

Publisher

verified publishersimonbinder.eu

Memory-efficient, streaming implementation of the tar file format

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

charcode, chunked_stream, meta, synchronized, typed_data

More

Packages that depend on tar