commit | 0c63561678d072eb2f45c8fcf224e1589d42aece | [log] [tgz] |
---|---|---|
author | Simon Binder <oss@simonbinder.eu> | Thu Dec 24 16:17:44 2020 +0100 |
committer | Simon Binder <oss@simonbinder.eu> | Thu Dec 24 16:17:44 2020 +0100 |
tree | a78de2dd68c4b4156ffc72a22ed3f1c28620f8b4 | |
parent | fb20876b949dc97ec9791638b05c2360341bd79b [diff] |
Publish for real
This package provides stream-based readers and writers for tar files.
When working with large tar files, this library consumes considerably less memory than package:archive, although it is slightly slower.
To read entries from a tar file, use
import 'dart:io'; import 'package:tar/tar.dart' as tar; Future<void> main() async { final tarFile = File('file.tar') .openRead() .transform(tar.reader); await for (final entry in tarFile) { print(entry.name); print(await entry.transform(utf8.decoder).first); } }
To read .tar.gz
files, transform the stream with gzip.decoder
first.
You can write tar files into a StreamSink<List<int>>
, such as an IOSink
:
import 'dart:io'; import 'package:tar/tar.dart' as tar; Future<void> main() async { final output = File('test.tar').openWrite(); await Stream<tar.Entry>.value( tar.MemoryEntry( tar.Header( name: 'hello.txt', mode: int.parse('644', radix: 8), ), utf8.encode('Hello world'), ), ).pipe(tar.WritingSink(output)); }
Note that tar files are always written in the format defined by the POSIX.1-2001 specification (--format=posix
in GNU tar).