Roll tar to 0.5.5+1 (#3447)

diff --git a/lib/src/third_party/tar/README.md b/lib/src/third_party/tar/README.md
index a2a220f..a2fbf7b 100644
--- a/lib/src/third_party/tar/README.md
+++ b/lib/src/third_party/tar/README.md
@@ -4,4 +4,4 @@
 tar-archives.
 
  * Repository: `https://github.com/simolus3/tar/`
- * Revision: `7cdb563c9894600c6a739ec268f8673d6122006f`
+ * Revision: `901ae404e0a225d9b08e5253415ca092f5c08706`
diff --git a/lib/src/third_party/tar/src/charcodes.dart b/lib/src/third_party/tar/src/charcodes.dart
index 1d34a6d..de0762f 100644
--- a/lib/src/third_party/tar/src/charcodes.dart
+++ b/lib/src/third_party/tar/src/charcodes.dart
@@ -1,3 +1,6 @@
+@internal
+import 'package:meta/meta.dart';
+
 /// "Line feed" control character.
 const int $lf = 0x0a;
 
diff --git a/lib/src/third_party/tar/src/constants.dart b/lib/src/third_party/tar/src/constants.dart
index 05accb0..d74a2b0 100644
--- a/lib/src/third_party/tar/src/constants.dart
+++ b/lib/src/third_party/tar/src/constants.dart
@@ -1,8 +1,11 @@
+@internal
 import 'dart:typed_data';
 
+import 'package:meta/meta.dart';
+
 import 'charcodes.dart';
 import 'exception.dart';
-import 'header.dart' show TarHeader; // for dartdoc
+import 'header.dart';
 
 // Magic values to help us identify the TAR header type.
 const magicGnu = [$u, $s, $t, $a, $r, $space]; // 'ustar '
@@ -11,74 +14,6 @@
 const versionUstar = [$0, $0]; // '00'
 const trailerStar = [$t, $a, $r, 0]; // 'tar\x00'
 
-/// Type flags for [TarHeader].
-///
-/// The type flag of a header indicates the kind of file associated with the
-/// entry. This enum contains the various type flags over the different TAR
-/// formats, and users should be careful that the type flag corresponds to the
-/// TAR format they are working with.
-enum TypeFlag {
-  /// [reg] indicates regular files.
-  ///
-  /// Old tar implementations have a seperate `TypeRegA` value. This library
-  /// will transparently read those as [regA].
-  reg,
-
-  /// Legacy-version of [reg] in old tar implementations.
-  ///
-  /// This is only used internally.
-  regA,
-
-  /// Hard link - header-only, may not have a data body
-  link,
-
-  /// Symbolic link - header-only, may not have a data body
-  symlink,
-
-  /// Character device node - header-only, may not have a data body
-  char,
-
-  /// Block device node - header-only, may not have a data body
-  block,
-
-  /// Directory - header-only, may not have a data body
-  dir,
-
-  /// FIFO node - header-only, may not have a data body
-  fifo,
-
-  /// Currently does not have any meaning, but is reserved for the future.
-  reserved,
-
-  /// Used by the PAX format to store key-value records that are only relevant
-  /// to the next file.
-  ///
-  /// This package transparently handles these types.
-  xHeader,
-
-  /// Used by the PAX format to store key-value records that are relevant to all
-  /// subsequent files.
-  ///
-  /// This package only supports parsing and composing such headers,
-  /// but does not currently support persisting the global state across files.
-  xGlobalHeader,
-
-  /// Indiates a sparse file in the GNU format
-  gnuSparse,
-
-  /// Used by the GNU format for a meta file to store the path or link name for
-  /// the next file.
-  /// This package transparently handles these types.
-  gnuLongName,
-  gnuLongLink,
-
-  /// Vendor specific typeflag, as defined in POSIX.1-1998. Seen as outdated but
-  /// may still exist on old files.
-  ///
-  /// This library uses a single enum to catch them all.
-  vendor
-}
-
 /// Generates the corresponding [TypeFlag] associated with [byte].
 TypeFlag typeflagFromByte(int byte) {
   switch (byte) {
diff --git a/lib/src/third_party/tar/src/entry.dart b/lib/src/third_party/tar/src/entry.dart
index 160974b..71d1730 100644
--- a/lib/src/third_party/tar/src/entry.dart
+++ b/lib/src/third_party/tar/src/entry.dart
@@ -2,7 +2,6 @@
 
 import 'package:meta/meta.dart';
 
-import 'constants.dart';
 import 'header.dart';
 
 /// An entry in a tar file.
diff --git a/lib/src/third_party/tar/src/format.dart b/lib/src/third_party/tar/src/format.dart
index b6be2f5..ef65ec9 100644
--- a/lib/src/third_party/tar/src/format.dart
+++ b/lib/src/third_party/tar/src/format.dart
@@ -28,7 +28,7 @@
   int get hashCode => _value;
 
   @override
-  bool operator ==(Object? other) {
+  bool operator ==(Object other) {
     if (other is! TarFormat) return false;
 
     return _value == other._value;
diff --git a/lib/src/third_party/tar/src/header.dart b/lib/src/third_party/tar/src/header.dart
index f28dc79..2f35662 100644
--- a/lib/src/third_party/tar/src/header.dart
+++ b/lib/src/third_party/tar/src/header.dart
@@ -7,6 +7,74 @@
 import 'format.dart';
 import 'utils.dart';
 
+/// Type flags for [TarHeader].
+///
+/// The type flag of a header indicates the kind of file associated with the
+/// entry. This enum contains the various type flags over the different TAR
+/// formats, and users should be careful that the type flag corresponds to the
+/// TAR format they are working with.
+enum TypeFlag {
+  /// [reg] indicates regular files.
+  ///
+  /// Old tar implementations have a seperate `TypeRegA` value. This library
+  /// will transparently read those as [regA].
+  reg,
+
+  /// Legacy-version of [reg] in old tar implementations.
+  ///
+  /// This is only used internally.
+  regA,
+
+  /// Hard link - header-only, may not have a data body
+  link,
+
+  /// Symbolic link - header-only, may not have a data body
+  symlink,
+
+  /// Character device node - header-only, may not have a data body
+  char,
+
+  /// Block device node - header-only, may not have a data body
+  block,
+
+  /// Directory - header-only, may not have a data body
+  dir,
+
+  /// FIFO node - header-only, may not have a data body
+  fifo,
+
+  /// Currently does not have any meaning, but is reserved for the future.
+  reserved,
+
+  /// Used by the PAX format to store key-value records that are only relevant
+  /// to the next file.
+  ///
+  /// This package transparently handles these types.
+  xHeader,
+
+  /// Used by the PAX format to store key-value records that are relevant to all
+  /// subsequent files.
+  ///
+  /// This package only supports parsing and composing such headers,
+  /// but does not currently support persisting the global state across files.
+  xGlobalHeader,
+
+  /// Indiates a sparse file in the GNU format
+  gnuSparse,
+
+  /// Used by the GNU format for a meta file to store the path or link name for
+  /// the next file.
+  /// This package transparently handles these types.
+  gnuLongName,
+  gnuLongLink,
+
+  /// Vendor specific typeflag, as defined in POSIX.1-1998. Seen as outdated but
+  /// may still exist on old files.
+  ///
+  /// This library uses a single enum to catch them all.
+  vendor
+}
+
 /// Header of a tar entry
 ///
 /// A tar header stores meta-information about the matching tar entry, such as
diff --git a/lib/src/third_party/tar/src/sparse.dart b/lib/src/third_party/tar/src/sparse.dart
index 06b88b1..35c0311 100644
--- a/lib/src/third_party/tar/src/sparse.dart
+++ b/lib/src/third_party/tar/src/sparse.dart
@@ -1,3 +1,4 @@
+@internal
 import 'package:async/async.dart';
 import 'package:meta/meta.dart';
 
@@ -21,7 +22,7 @@
   String toString() => 'offset: $offset, length $length';
 
   @override
-  bool operator ==(Object? other) {
+  bool operator ==(Object other) {
     if (other is! SparseEntry) return false;
 
     return offset == other.offset && length == other.length;
diff --git a/lib/src/third_party/tar/src/utils.dart b/lib/src/third_party/tar/src/utils.dart
index 4fa75b1..e2bb5b6 100644
--- a/lib/src/third_party/tar/src/utils.dart
+++ b/lib/src/third_party/tar/src/utils.dart
@@ -1,8 +1,11 @@
+@internal
 import 'dart:async';
 import 'dart:convert';
 import 'dart:math';
 import 'dart:typed_data';
 
+import 'package:meta/meta.dart';
+
 import 'charcodes.dart';
 import 'constants.dart';
 import 'exception.dart';
@@ -95,7 +98,7 @@
   int computeUnsignedHeaderChecksum() {
     // Accessing the last element first helps the VM eliminate bounds checks in
     // the loops below.
-    this[blockSize - 1];
+    this[blockSize - 1]; // ignore: unnecessary_statements
     var result = checksumLength * _checksumPlaceholder;
 
     for (var i = 0; i < checksumOffset; i++) {
@@ -109,7 +112,7 @@
   }
 
   int computeSignedHeaderChecksum() {
-    this[blockSize - 1];
+    this[blockSize - 1]; // ignore: unnecessary_statements
     // Note that _checksumPlaceholder.toSigned(8) == _checksumPlaceholder
     var result = checksumLength * _checksumPlaceholder;
 
@@ -445,7 +448,7 @@
 
     var state = _StreamState.initial;
 
-    /// Sends trailing data to the stream. Reeturns true if the subscription
+    /// Sends trailing data to the stream. Returns true if the subscription
     /// should still be resumed afterwards.
     bool emitTrailing() {
       // Attempt to serve requests from pending data first.
@@ -512,13 +515,25 @@
     controller
       ..onListen = scheduleInitialEmit
       ..onPause = () {
-        assert(state == _StreamState.initial || state == _StreamState.attached);
+        assert(
+            state == _StreamState.initial ||
+                state == _StreamState.attached ||
+                state == _StreamState.done,
+            'Unexpected pause event in $state ($_remainingBlocksInOutgoing blocks remaining).');
 
         if (state == _StreamState.initial) {
           state = _StreamState.pausedAfterInitial;
-        } else {
+        } else if (state == _StreamState.attached) {
           _pause();
           state = _StreamState.pausedAfterAttached;
+        } else if (state == _StreamState.done) {
+          // It may happen that onPause is called in a state where we believe
+          // the stream to be done already. After the stream is done, we close
+          // the controller in a new microtask. So if the subscription is paused
+          // after the last event it emitted but before we close the controller,
+          // we can get a pause event here.
+          // There's nothing to do in that case.
+          assert(_subscription?.isPaused != false);
         }
       }
       ..onResume = () {
diff --git a/lib/src/third_party/tar/tar.dart b/lib/src/third_party/tar/tar.dart
index 14247bd..9948c4f 100644
--- a/lib/src/third_party/tar/tar.dart
+++ b/lib/src/third_party/tar/tar.dart
@@ -8,10 +8,9 @@
 import 'src/reader.dart';
 import 'src/writer.dart';
 
-export 'src/constants.dart' show TypeFlag;
 export 'src/entry.dart' show TarEntry, SynchronousTarEntry;
 export 'src/exception.dart';
 export 'src/format.dart';
-export 'src/header.dart' show TarHeader;
+export 'src/header.dart' show TarHeader, TypeFlag;
 export 'src/reader.dart' show TarReader;
 export 'src/writer.dart';