Replace all async functions with sync
diff --git a/lib/src/archive/archive.dart b/lib/src/archive/archive.dart
index f56d71f..331df00 100644
--- a/lib/src/archive/archive.dart
+++ b/lib/src/archive/archive.dart
@@ -3,8 +3,7 @@
/// A collection of files
class Archive extends ArchiveDirectory {
- Archive([String name = ''])
- : super(name);
+ Archive([String name = '']) : super(name);
ArchiveDirectory _getOrCreateDirectory(String name) {
final index = entryMap[name];
diff --git a/lib/src/archive/archive_directory.dart b/lib/src/archive/archive_directory.dart
index f695350..52066f6 100644
--- a/lib/src/archive/archive_directory.dart
+++ b/lib/src/archive/archive_directory.dart
@@ -11,7 +11,7 @@
bool get isFile => false;
@override
- Future<void> close() async {}
+ void close() {}
/// Add a file to the archive.
void addEntry(ArchiveEntry entry) {
@@ -45,15 +45,16 @@
return dir;
}
- Future<void> clear() async {
- final futures = <Future<void>>[];
+ void clear() {
+ //final futures = <Future<void>>[];
for (final fp in entries) {
- futures.add(fp.close());
+ fp.close();
+ //futures.add(fp.close());
}
entries.clear();
entryMap.clear();
comment = null;
- await Future.wait(futures);
+ //Future.wait(futures);
}
/// The number of files in the archive.
diff --git a/lib/src/archive/archive_entry.dart b/lib/src/archive/archive_entry.dart
index d1e7401..47a6228 100644
--- a/lib/src/archive/archive_entry.dart
+++ b/lib/src/archive/archive_entry.dart
@@ -28,7 +28,7 @@
String get fullPathName =>
parent != null ? '${parent!.fullPathName}/$name' : name;
- Future<void> close();
+ void close();
@override
ArchiveEntry get first => this;
diff --git a/lib/src/archive/archive_file.dart b/lib/src/archive/archive_file.dart
index 51827bc..a52fd8f 100644
--- a/lib/src/archive/archive_file.dart
+++ b/lib/src/archive/archive_file.dart
@@ -51,19 +51,18 @@
_rawContent = file;
}
- Future<void> writeContent(OutputStream output,
- {bool freeMemory = true}) async {
+ void writeContent(OutputStream output, {bool freeMemory = true}) {
if (_content == null) {
if (_rawContent == null) {
return;
}
- await decompress(output);
+ decompress(output);
}
- await _content?.write(output);
+ _content?.write(output);
if (freeMemory && _content != null) {
- await _content!.close();
+ _content!.close();
_content = null;
}
}
@@ -72,9 +71,9 @@
FileContent? get rawContent => _rawContent;
/// Get the content of the file, decompressing on demand as necessary.
- Future<InputStream?> getContent() async {
+ InputStream? getContent() {
if (_content == null) {
- await decompress();
+ decompress();
}
return _content?.getStream();
}
@@ -83,39 +82,41 @@
_content = null;
}
- Future<Uint8List?> readBytes() async {
- final stream = await getContent();
+ Uint8List? readBytes() {
+ final stream = getContent();
return stream?.toUint8List();
}
@override
- Future<void> close() async {
- final futures = <Future<void>>[];
+ void close() {
+ //final futures = <Future<void>>[];
if (_content != null) {
- futures.add(_content!.close());
+ _content!.close();
+ //futures.add(_content!.close());
}
if (_rawContent != null) {
- futures.add(_rawContent!.close());
+ _rawContent!.close();
+ //futures.add(_rawContent!.close());
}
_content = null;
_rawContent = null;
- await Future.wait(futures);
+ //Future.wait(futures);
}
/// If the file data is compressed, decompress it.
- Future<void> decompress([OutputStream? output]) async {
+ void decompress([OutputStream? output]) {
if (_content == null && _rawContent != null) {
if (compression != CompressionType.none) {
if (output != null) {
- await _rawContent!.decompress(output);
+ _rawContent!.decompress(output);
} else {
- final rawStream = await _rawContent!.getStream();
- final bytes = await rawStream.toUint8List();
+ final rawStream = _rawContent!.getStream();
+ final bytes = rawStream.toUint8List();
_content = FileContentMemory(bytes);
}
} else {
if (output != null) {
- await output.writeStream(await _rawContent!.getStream());
+ output.writeStream(_rawContent!.getStream());
} else {
_content = _rawContent;
}
diff --git a/lib/src/codecs/zip/zip_directory.dart b/lib/src/codecs/zip/zip_directory.dart
index 34adbbc..f61c8c8 100644
--- a/lib/src/codecs/zip/zip_directory.dart
+++ b/lib/src/codecs/zip/zip_directory.dart
@@ -20,42 +20,42 @@
String zipFileComment = '';
final fileHeaders = <ZipFileHeader>[];
- Future<void> read(InputStream input, {String? password}) async {
- filePosition = await _findSignature(input);
- await input.setPosition(filePosition);
- final sig = await input.readUint32();
+ void read(InputStream input, {String? password}) {
+ filePosition = _findSignature(input);
+ input.setPosition(filePosition);
+ final sig = input.readUint32();
if (sig != signature) {
throw ArchiveException('Could not find End of Central Directory Record');
}
- numberOfThisDisk = await input.readUint16();
- diskWithTheStartOfTheCentralDirectory = await input.readUint16();
- totalCentralDirectoryEntriesOnThisDisk = await input.readUint16();
- totalCentralDirectoryEntries = await input.readUint16();
- centralDirectorySize = await input.readUint32();
- centralDirectoryOffset = await input.readUint32();
+ numberOfThisDisk = input.readUint16();
+ diskWithTheStartOfTheCentralDirectory = input.readUint16();
+ totalCentralDirectoryEntriesOnThisDisk = input.readUint16();
+ totalCentralDirectoryEntries = input.readUint16();
+ centralDirectorySize = input.readUint32();
+ centralDirectoryOffset = input.readUint32();
- final len = await input.readUint16();
+ final len = input.readUint16();
if (len > 0) {
- zipFileComment = await input.readString(size: len, utf8: false);
+ zipFileComment = input.readString(size: len, utf8: false);
}
- await _readZip64Data(input);
+ _readZip64Data(input);
- final dirContent = await input.subset(
+ final dirContent = input.subset(
position: centralDirectoryOffset, length: centralDirectorySize);
while (!dirContent.isEOS) {
- final fileSig = await dirContent.readUint32();
+ final fileSig = dirContent.readUint32();
if (fileSig != ZipFileHeader.signature) {
break;
}
- final header = ZipFileHeader();
- await header.read(dirContent, fileBytes: input, password: password);
+ final header = ZipFileHeader()
+ ..read(dirContent, fileBytes: input, password: password);
fileHeaders.add(header);
}
}
- Future<void> _readZip64Data(InputStream input) async {
+ void _readZip64Data(InputStream input) {
final ip = input.position;
// Check for zip64 data.
@@ -72,21 +72,20 @@
if (locPos < 0) {
return;
}
- final zip64 =
- await input.subset(position: locPos, length: zip64EocdLocatorSize);
+ final zip64 = input.subset(position: locPos, length: zip64EocdLocatorSize);
- var sig = await zip64.readUint32();
+ var sig = zip64.readUint32();
// If this isn't the signature we're looking for, nothing more to do.
if (sig != zip64EocdLocatorSignature) {
- await input.setPosition(ip);
+ input.setPosition(ip);
return;
}
- /*final startZip64Disk =*/ await zip64.readUint32();
- final zip64DirOffset = await zip64.readUint64();
- /*final numZip64Disks =*/ await zip64.readUint32();
+ /*final startZip64Disk =*/ zip64.readUint32();
+ final zip64DirOffset = zip64.readUint64();
+ /*final numZip64Disks =*/ zip64.readUint32();
- await input.setPosition(zip64DirOffset);
+ input.setPosition(zip64DirOffset);
// Zip64 end of central directory record
// signature 4 bytes (0x06064b50)
@@ -106,21 +105,22 @@
// directory with respect to
// the starting disk number 8 bytes
// zip64 extensible data sector (variable size)
- sig = await input.readUint32();
+ sig = input.readUint32();
if (sig != zip64EocdSignature) {
- await input.setPosition(ip);
+ input.setPosition(ip);
return;
}
- /*final zip64EOCDSize =*/ await input.readUint64();
- /*final zip64Version =*/ await input.readUint16();
- /*final zip64VersionNeeded =*/ await input.readUint16();
- final zip64DiskNumber = await input.readUint32();
- final zip64StartDisk = await input.readUint32();
- final zip64NumEntriesOnDisk = await input.readUint64();
- final zip64NumEntries = await input.readUint64();
- final dirSize = await input.readUint64();
- final dirOffset = await input.readUint64();
+ /*final zip64EOCDSize =*/ input
+ ..readUint64()
+ /*final zip64Version =*/ ..readUint16() /*final zip64VersionNeeded =*/
+ ..readUint16();
+ final zip64DiskNumber = input.readUint32();
+ final zip64StartDisk = input.readUint32();
+ final zip64NumEntriesOnDisk = input.readUint64();
+ final zip64NumEntries = input.readUint64();
+ final dirSize = input.readUint64();
+ final dirOffset = input.readUint64();
numberOfThisDisk = zip64DiskNumber;
diskWithTheStartOfTheCentralDirectory = zip64StartDisk;
@@ -129,10 +129,10 @@
centralDirectorySize = dirSize;
centralDirectoryOffset = dirOffset;
- await input.setPosition(ip);
+ input.setPosition(ip);
}
- Future<int> _findSignature(InputStream input) async {
+ int _findSignature(InputStream input) {
final pos = input.position;
final length = input.length;
@@ -140,10 +140,10 @@
// file. We need to search from the end to find these structures,
// starting with the 'End of central directory' record (EOCD).
for (var ip = length - 5; ip >= 0; --ip) {
- await input.setPosition(ip);
- final sig = await input.readUint32();
+ input.setPosition(ip);
+ final sig = input.readUint32();
if (sig == signature) {
- await input.setPosition(pos);
+ input.setPosition(pos);
return ip;
}
}
diff --git a/lib/src/codecs/zip/zip_file.dart b/lib/src/codecs/zip/zip_file.dart
index e78f078..97f583a 100644
--- a/lib/src/codecs/zip/zip_file.dart
+++ b/lib/src/codecs/zip/zip_file.dart
@@ -61,25 +61,25 @@
ZipFile(this.header);
- Future<void> read(InputStream input, {String? password}) async {
- final sig = await input.readUint32();
+ void read(InputStream input, {String? password}) {
+ final sig = input.readUint32();
if (sig != zipSignature) {
throw ArchiveException('Invalid Zip Signature');
}
- version = await input.readUint16();
- flags = await input.readUint16();
- final compression = await input.readUint16();
+ version = input.readUint16();
+ flags = input.readUint16();
+ final compression = input.readUint16();
compressionMethod = _compressionTypes[compression] ?? CompressionType.none;
- lastModFileTime = await input.readUint16();
- lastModFileDate = await input.readUint16();
- crc32 = await input.readUint32();
- compressedSize = await input.readUint32();
- uncompressedSize = await input.readUint32();
- final fnLen = await input.readUint16();
- final exLen = await input.readUint16();
- filename = await input.readString(size: fnLen);
- extraField = await (await input.readBytes(exLen)).toUint8List();
+ lastModFileTime = input.readUint16();
+ lastModFileDate = input.readUint16();
+ crc32 = input.readUint32();
+ compressedSize = input.readUint32();
+ uncompressedSize = input.readUint32();
+ final fnLen = input.readUint16();
+ final exLen = input.readUint16();
+ filename = input.readString(size: fnLen);
+ extraField = input.readBytes(exLen).toUint8List();
_encryptionType =
(flags & 0x1) != 0 ? EncryptionMode.zipCrypto : EncryptionMode.none;
@@ -87,17 +87,17 @@
_password = password;
// Read compressedSize bytes for the compressed data.
- _rawContent = await input.readBytes(header!.compressedSize);
+ _rawContent = input.readBytes(header!.compressedSize);
if (_encryptionType != EncryptionMode.none && exLen > 2) {
final extra = InputStreamMemory(extraField);
- final id = await extra.readUint16();
+ final id = extra.readUint16();
if (id == AesHeader.signature) {
- await extra.readUint16(); // dataSize = 7
- final vendorVersion = await extra.readUint16();
- final vendorId = await extra.readString(size: 2);
- final encryptionStrength = await extra.readByte();
- final compressionMethod = await extra.readUint16();
+ extra.readUint16(); // dataSize = 7
+ final vendorVersion = extra.readUint16();
+ final vendorId = extra.readString(size: 2);
+ final encryptionStrength = extra.readByte();
+ final compressionMethod = extra.readUint16();
_encryptionType = EncryptionMode.aes;
_aesHeader = AesHeader(
@@ -121,62 +121,62 @@
// appended in a 12-byte structure (optionally preceded by a 4-byte
// signature) immediately after the compressed data:
if (flags & 0x08 != 0) {
- final sigOrCrc = await input.readUint32();
+ final sigOrCrc = input.readUint32();
if (sigOrCrc == 0x08074b50) {
- crc32 = await input.readUint32();
+ crc32 = input.readUint32();
} else {
crc32 = sigOrCrc;
}
- compressedSize = await input.readUint32();
- uncompressedSize = await input.readUint32();
+ compressedSize = input.readUint32();
+ uncompressedSize = input.readUint32();
}
}
/// This will decompress the data (if necessary) in order to calculate the
/// crc32 checksum for the decompressed data and verify it with the value
/// stored in the zip.
- Future<bool> verifyCrc32() async {
- final contentStream = await getStream();
- _computedCrc32 ??= getCrc32List(await contentStream.toUint8List());
+ bool verifyCrc32() {
+ final contentStream = getStream();
+ _computedCrc32 ??= getCrc32List(contentStream.toUint8List());
return _computedCrc32 == crc32;
}
@override
- Future<void> decompress(OutputStream output) async {
+ void decompress(OutputStream output) {
if (_encryptionType != EncryptionMode.none) {
if (_rawContent.length <= 0) {
- _content = await _rawContent.toUint8List();
+ _content = _rawContent.toUint8List();
_encryptionType = EncryptionMode.none;
} else {
if (_encryptionType == EncryptionMode.zipCrypto) {
- _rawContent = await _decodeZipCrypto(_rawContent);
+ _rawContent = _decodeZipCrypto(_rawContent);
} else if (_encryptionType == EncryptionMode.aes) {
- _rawContent = await _decodeAes(_rawContent);
+ _rawContent = _decodeAes(_rawContent);
}
_encryptionType = EncryptionMode.none;
}
}
- final decompress = Inflate.stream(_rawContent,
- uncompressedSize: uncompressedSize, output: output);
- await decompress.inflate();
+ Inflate.stream(_rawContent,
+ uncompressedSize: uncompressedSize, output: output)
+ .inflate();
}
/// Get the decompressed content from the file. The file isn't decompressed
/// until it is requested.
@override
- Future<InputStream> getStream() async {
+ InputStream getStream() {
if (_content == null) {
if (_encryptionType != EncryptionMode.none) {
if (_rawContent.length <= 0) {
- _content = await _rawContent.toUint8List();
+ _content = _rawContent.toUint8List();
_encryptionType = EncryptionMode.none;
} else {
if (_encryptionType == EncryptionMode.zipCrypto) {
- _rawContent = await _decodeZipCrypto(_rawContent);
+ _rawContent = _decodeZipCrypto(_rawContent);
} else if (_encryptionType == EncryptionMode.aes) {
- _rawContent = await _decodeAes(_rawContent);
+ _rawContent = _decodeAes(_rawContent);
}
_encryptionType = EncryptionMode.none;
}
@@ -184,19 +184,19 @@
if (compressionMethod == CompressionType.deflate) {
final decompress =
- Inflate.stream(_rawContent, uncompressedSize: uncompressedSize);
- await decompress.inflate();
- _content = await decompress.getBytes();
+ Inflate.stream(_rawContent, uncompressedSize: uncompressedSize)
+ ..inflate();
+ _content = decompress.getBytes();
compressionMethod = CompressionType.none;
} else {
- _content = await _rawContent.toUint8List();
+ _content = _rawContent.toUint8List();
}
}
return InputStreamMemory(_content!);
}
- Future<Uint8List> getRawContent() async {
+ Uint8List getRawContent() {
if (_content != null) {
return _content!;
}
@@ -232,11 +232,11 @@
_updateKeys(c);
}
- Future<InputStream> _decodeZipCrypto(InputStream input) async {
+ InputStream _decodeZipCrypto(InputStream input) {
for (var i = 0; i < 12; ++i) {
- _decodeByte(await _rawContent.readByte());
+ _decodeByte(_rawContent.readByte());
}
- final bytes = await _rawContent.toUint8List();
+ final bytes = _rawContent.toUint8List();
for (var i = 0; i < bytes.length; ++i) {
final temp = bytes[i] ^ _decryptByte();
_updateKeys(temp);
@@ -245,27 +245,26 @@
return InputStreamMemory(bytes);
}
- Future<InputStream> _decodeAes(InputStream input) async {
+ InputStream _decodeAes(InputStream input) {
Uint8List salt;
if (_aesHeader!.encryptionStrength == 1) {
// 128-bit
- salt = await (await input.readBytes(8)).toUint8List();
+ salt = input.readBytes(8).toUint8List();
} else if (_aesHeader!.encryptionStrength == 1) {
// 192-bit
- salt = await (await input.readBytes(12)).toUint8List();
+ salt = input.readBytes(12).toUint8List();
} else {
// 256-bit
- salt = await (await input.readBytes(16)).toUint8List();
+ salt = input.readBytes(16).toUint8List();
}
//int verification = input.readUint16();
- final dataBytes = await input.readBytes(input.length - 10);
- final bytes = await dataBytes.toUint8List();
+ final dataBytes = input.readBytes(input.length - 10);
+ final bytes = dataBytes.toUint8List();
final key = _deriveKey(_password!, salt);
- AesDecrypt(key)
- .decryptCrt(bytes);
+ AesDecrypt(key).decryptCrt(bytes);
return InputStreamMemory(bytes);
}
@@ -281,17 +280,16 @@
const iterationCount = 1000;
final params = Pbkdf2Parameters(salt, iterationCount, derivedKeyLength);
final keyDerivator = PBKDF2KeyDerivator(HMac(SHA256Digest(), 64))
- ..init(params);
+ ..init(params);
return keyDerivator.process(passwordBytes);
}
@override
- Future<void> close() async {
+ void close() {
_content = null;
}
@override
- Future<void> write(OutputStream output) async =>
- output.writeStream(await getStream());
+ void write(OutputStream output) => output.writeStream(getStream());
}
diff --git a/lib/src/codecs/zip/zip_file_header.dart b/lib/src/codecs/zip/zip_file_header.dart
index 0c40b11..90f3920 100644
--- a/lib/src/codecs/zip/zip_file_header.dart
+++ b/lib/src/codecs/zip/zip_file_header.dart
@@ -21,37 +21,36 @@
String fileComment = '';
ZipFile? file;
- Future<void> read(InputStream input,
- {InputStream? fileBytes, String? password}) async {
- versionMadeBy = await input.readUint16();
- versionNeededToExtract = await input.readUint16();
- generalPurposeBitFlag = await input.readUint16();
- compressionMethod = await input.readUint16();
- lastModifiedFileTime = await input.readUint16();
- lastModifiedFileDate = await input.readUint16();
- crc32 = await input.readUint32();
- compressedSize = await input.readUint32();
- uncompressedSize = await input.readUint32();
- final fnameLen = await input.readUint16();
- final extraLen = await input.readUint16();
- final commentLen = await input.readUint16();
- diskNumberStart = await input.readUint16();
- internalFileAttributes = await input.readUint16();
- externalFileAttributes = await input.readUint32();
- localHeaderOffset = await input.readUint32();
+ void read(InputStream input, {InputStream? fileBytes, String? password}) {
+ versionMadeBy = input.readUint16();
+ versionNeededToExtract = input.readUint16();
+ generalPurposeBitFlag = input.readUint16();
+ compressionMethod = input.readUint16();
+ lastModifiedFileTime = input.readUint16();
+ lastModifiedFileDate = input.readUint16();
+ crc32 = input.readUint32();
+ compressedSize = input.readUint32();
+ uncompressedSize = input.readUint32();
+ final fnameLen = input.readUint16();
+ final extraLen = input.readUint16();
+ final commentLen = input.readUint16();
+ diskNumberStart = input.readUint16();
+ internalFileAttributes = input.readUint16();
+ externalFileAttributes = input.readUint32();
+ localHeaderOffset = input.readUint32();
if (fnameLen > 0) {
- filename = await input.readString(size: fnameLen);
+ filename = input.readString(size: fnameLen);
}
if (extraLen > 0) {
- final extra = await input.readBytes(extraLen);
- extraField = await extra.toUint8List();
+ final extra = input.readBytes(extraLen);
+ extraField = extra.toUint8List();
// Rewind to start of the extra fields to read field by field.
- await extra.rewind(extraLen);
+ extra.rewind(extraLen);
- final id = await extra.readUint16();
- var size = await extra.readUint16();
+ final id = extra.readUint16();
+ var size = extra.readUint16();
if (id == 1) {
// Zip64 extended information
// The following is the layout of the zip64 extended
@@ -73,32 +72,32 @@
// Number 4 bytes Number of the disk on which
// this file starts
if (size >= 8 && uncompressedSize == 0xffffffff) {
- uncompressedSize = await extra.readUint64();
+ uncompressedSize = extra.readUint64();
size -= 8;
}
if (size >= 8 && compressedSize == 0xffffffff) {
- compressedSize = await extra.readUint64();
+ compressedSize = extra.readUint64();
size -= 8;
}
if (size >= 8 && localHeaderOffset == 0xffffffff) {
- localHeaderOffset = await extra.readUint64();
+ localHeaderOffset = extra.readUint64();
size -= 8;
}
if (size >= 4 && diskNumberStart == 0xffff) {
- diskNumberStart = await extra.readUint32();
+ diskNumberStart = extra.readUint32();
size -= 4;
}
}
}
if (commentLen > 0) {
- fileComment = await input.readString(size: commentLen);
+ fileComment = input.readString(size: commentLen);
}
if (fileBytes != null) {
- await fileBytes.setPosition(localHeaderOffset);
+ fileBytes.setPosition(localHeaderOffset);
file = ZipFile(this);
- await file!.read(fileBytes, password: password);
+ file!.read(fileBytes, password: password);
}
}
diff --git a/lib/src/codecs/zip_decoder.dart b/lib/src/codecs/zip_decoder.dart
index b9b4562..9e2a860 100644
--- a/lib/src/codecs/zip_decoder.dart
+++ b/lib/src/codecs/zip_decoder.dart
@@ -15,17 +15,17 @@
class ZipDecoder {
late ZipDirectory directory;
- Future<Archive> decodeBytes(Uint8List data,
+ Archive decodeBytes(Uint8List data,
{bool verify = false, String? password}) =>
decodeStream(InputStreamMemory(data), verify: verify, password: password);
- Future<Archive> decodeStream(
+ Archive decodeStream(
InputStream input, {
bool verify = false,
String? password,
- }) async {
+ }) {
directory = ZipDirectory();
- await directory.read(input, password: password);
+ directory.read(input, password: password);
final archive = Archive();
for (final zfh in directory.fileHeaders) {
@@ -36,8 +36,8 @@
//final compress = zf.compressionMethod != ZipFile.store;
if (verify) {
- final stream = await zf.getStream();
- final computedCrc = getCrc32List(await stream.toUint8List());
+ final stream = zf.getStream();
+ final computedCrc = getCrc32List(stream.toUint8List());
if (computedCrc != zf.crc32) {
throw ArchiveException('Invalid CRC for file in archive.');
}
@@ -89,7 +89,7 @@
final fileType = entry.mode & 0xf000;
if (fileType == 0xa000) {
if (entry is ArchiveFile) {
- final bytes = await entry.readBytes();
+ final bytes = entry.readBytes();
if (bytes != null) {
entry.symbolicLink = utf8.decode(bytes);
}
diff --git a/lib/src/codecs/zlib/_inflate_buffer_io.dart b/lib/src/codecs/zlib/_inflate_buffer_io.dart
index 32fe4ab..e3e8123 100644
--- a/lib/src/codecs/zlib/_inflate_buffer_io.dart
+++ b/lib/src/codecs/zlib/_inflate_buffer_io.dart
@@ -1,6 +1,5 @@
-import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
-FutureOr<Uint8List>? inflateBuffer_(Uint8List data) =>
+Uint8List? inflateBuffer_(Uint8List data) =>
ZLibDecoder(raw: true).convert(data) as Uint8List;
diff --git a/lib/src/codecs/zlib/_inflate_buffer_stub.dart b/lib/src/codecs/zlib/_inflate_buffer_stub.dart
index 6e32d84..a40271f 100644
--- a/lib/src/codecs/zlib/_inflate_buffer_stub.dart
+++ b/lib/src/codecs/zlib/_inflate_buffer_stub.dart
@@ -1,6 +1,5 @@
-import 'dart:async';
import 'dart:typed_data';
-FutureOr<Uint8List>? inflateBuffer_(Uint8List data) {
+Uint8List? inflateBuffer_(Uint8List data) {
throw UnsupportedError('inflateBuffer requires html or io.');
}
diff --git a/lib/src/codecs/zlib/_inflate_buffer_web.dart b/lib/src/codecs/zlib/_inflate_buffer_web.dart
index eeb238c..9212cb9 100644
--- a/lib/src/codecs/zlib/_inflate_buffer_web.dart
+++ b/lib/src/codecs/zlib/_inflate_buffer_web.dart
@@ -1,6 +1,5 @@
-import 'dart:async';
import 'dart:typed_data';
import 'inflate.dart';
-FutureOr<Uint8List>? inflateBuffer_(Uint8List data) => Inflate(data).getBytes();
+Uint8List? inflateBuffer_(Uint8List data) => Inflate(data).getBytes();
diff --git a/lib/src/codecs/zlib/_zlib_decoder_io.dart b/lib/src/codecs/zlib/_zlib_decoder_io.dart
index dbe76a5..b27f301 100644
--- a/lib/src/codecs/zlib/_zlib_decoder_io.dart
+++ b/lib/src/codecs/zlib/_zlib_decoder_io.dart
@@ -11,11 +11,10 @@
const _ZLibDecoder();
@override
- Future<Uint8List> decodeBytes(Uint8List data, {bool verify = false}) async =>
+ Uint8List decodeBytes(Uint8List data, {bool verify = false}) =>
ZLibCodec().decoder.convert(data) as Uint8List;
@override
- Future<Uint8List> decodeStream(InputStream input,
- {bool verify = false}) async =>
- decodeBytes(await input.toUint8List(), verify: verify);
+ Uint8List decodeStream(InputStream input, {bool verify = false}) =>
+ decodeBytes(input.toUint8List(), verify: verify);
}
diff --git a/lib/src/codecs/zlib/_zlib_decoder_web.dart b/lib/src/codecs/zlib/_zlib_decoder_web.dart
index adece46..eb9aaab 100644
--- a/lib/src/codecs/zlib/_zlib_decoder_web.dart
+++ b/lib/src/codecs/zlib/_zlib_decoder_web.dart
@@ -17,13 +17,12 @@
const _ZLibDecoder();
@override
- Future<Uint8List> decodeBytes(Uint8List data, {bool verify = false}) async =>
+ Uint8List decodeBytes(Uint8List data, {bool verify = false}) =>
decodeStream(InputStreamMemory(data, byteOrder: ByteOrder.bigEndian),
verify: verify);
@override
- Future<Uint8List> decodeStream(InputStream input,
- {bool verify = false}) async {
+ Uint8List decodeStream(InputStream input, {bool verify = false}) {
/*
* The zlib format has the following structure:
* CMF 1 byte
@@ -41,8 +40,8 @@
* bits [5] FDICT (preset dictionary)
* bits [6, 7] FLEVEL (compression level)
*/
- final cmf = await input.readByte();
- final flg = await input.readByte();
+ final cmf = input.readByte();
+ final flg = input.readByte();
final method = cmf & 8;
final cinfo = (cmf >> 3) & 8; // ignore: unused_local_variable
@@ -61,15 +60,15 @@
}
if (fdict != 0) {
- /*dictid =*/ await input.readUint32();
+ /*dictid =*/ input.readUint32();
throw ArchiveException('FDICT Encoding not currently supported');
}
// Inflate
- final buffer = await Inflate.stream(input).getBytes();
+ final buffer = Inflate.stream(input).getBytes();
// verify adler-32
- final adler32 = await input.readUint32();
+ final adler32 = input.readUint32();
if (verify) {
final a = getAdler32(buffer);
if (adler32 != a) {
diff --git a/lib/src/codecs/zlib/deflate.dart b/lib/src/codecs/zlib/deflate.dart
index 1149d91..8784c01 100644
--- a/lib/src/codecs/zlib/deflate.dart
+++ b/lib/src/codecs/zlib/deflate.dart
@@ -39,36 +39,33 @@
_init(level);
}
- Future<int> deflate({FlushMode flush = FlushMode.finish}) =>
- _deflate(flush: flush);
+ int deflate({FlushMode flush = FlushMode.finish}) => _deflate(flush: flush);
- Future<void> finish() async =>
- _flushPending();
+ void finish() => _flushPending();
/// Get the resulting compressed bytes.
- Future<Uint8List> getBytes() async {
- await _flushPending();
+ Uint8List getBytes() {
+ _flushPending();
return output.getBytes();
}
/// Get the resulting compressed bytes without storing the resulting data to
/// minimize memory usage.
- Future<Uint8List> takeBytes() async {
- await _flushPending();
- final bytes = await output.getBytes();
- await output.clear();
+ Uint8List takeBytes() {
+ _flushPending();
+ final bytes = output.getBytes();
+ output.clear();
return bytes;
}
/// Add more data to be deflated.
- Future<void> addBytes(Uint8List bytes, {FlushMode flush = FlushMode.finish}) {
+ void addBytes(Uint8List bytes, {FlushMode flush = FlushMode.finish}) {
input = InputStreamMemory(bytes);
- return _deflate(flush: flush);
+ _deflate(flush: flush);
}
/// Add more data to be deflated.
- Future<int> addStream(InputStream buffer,
- {FlushMode flush = FlushMode.finish}) {
+ int addStream(InputStream buffer, {FlushMode flush = FlushMode.finish}) {
input = buffer;
return _deflate(flush: flush);
}
@@ -140,13 +137,13 @@
}
/// Compress the current input buffer.
- Future<int> _deflate({FlushMode flush = FlushMode.finish}) async {
+ int _deflate({FlushMode flush = FlushMode.finish}) {
// Flush as much pending output as possible
if (_pending != 0) {
// Make sure there is something to do and avoid duplicate consecutive
// flushes. For repeated and useless calls with FINISH, we keep
// returning Z_STREAM_END instead of Z_BUFF_ERROR.
- await _flushPending();
+ _flushPending();
}
// Start a block or continue the current one.
@@ -156,13 +153,13 @@
var bState = -1;
switch (_config.function) {
case stored:
- bState = await _deflateStored(flush);
+ bState = _deflateStored(flush);
break;
case fast:
- bState = await _deflateFast(flush);
+ bState = _deflateFast(flush);
break;
case slow:
- bState = await _deflateSlow(flush);
+ bState = _deflateSlow(flush);
break;
default:
break;
@@ -198,7 +195,7 @@
}
}
- await _flushPending();
+ _flushPending();
}
}
@@ -655,11 +652,11 @@
_putBytes(_window, buf, len);
}
- Future<void> _flushBlockOnly(bool eof) async {
+ void _flushBlockOnly(bool eof) {
_trFlushBlock(
_blockStart >= 0 ? _blockStart : -1, _strStart - _blockStart, eof);
_blockStart = _strStart;
- await _flushPending();
+ _flushPending();
}
// Copy without compression as much as possible from the input stream, return
@@ -669,7 +666,7 @@
// only for the level=0 compression option.
// NOTE: this function should be optimized to avoid extra copying from
// window to pending_buf.
- Future<int> _deflateStored(FlushMode flush) async {
+ int _deflateStored(FlushMode flush) {
// Stored blocks are limited to 0xffff bytes, pending_buf is limited
// to pending_buf_size, and each stored block has a 5 byte header:
var maxBlockSize = 0xffff;
@@ -682,7 +679,7 @@
while (true) {
// Fill the window as much as possible:
if (_lookAhead <= 1) {
- await _fillWindow();
+ _fillWindow();
if (_lookAhead == 0 && flush == FlushMode.none) {
return needMore;
@@ -702,17 +699,17 @@
if (_strStart >= maxStart) {
_lookAhead = _strStart - maxStart;
_strStart = maxStart;
- await _flushBlockOnly(false);
+ _flushBlockOnly(false);
}
// Flush if we may have to slide, otherwise block_start may become
// negative and the data will be gone:
if (_strStart - _blockStart >= _windowSize - minLookAhead) {
- await _flushBlockOnly(false);
+ _flushBlockOnly(false);
}
}
- await _flushBlockOnly(flush == FlushMode.finish);
+ _flushBlockOnly(flush == FlushMode.finish);
return (flush == FlushMode.finish) ? finishDone : blockDone;
}
@@ -794,7 +791,7 @@
// At least one byte has been read, or avail_in == 0; reads are
// performed for at least two bytes (required for the zip translate_eol
// option -- not supported here).
- Future<void> _fillWindow() async {
+ void _fillWindow() {
do {
// Amount of free space at the end of the window.
var more = _actualWindowSize - _lookAhead - _strStart;
@@ -852,7 +849,7 @@
// Otherwise, window_size == 2*WSIZE so more >= 2.
// If there was sliding, more >= WSIZE. So in all cases, more >= 2.
- final n = await _readBuf(_window, _strStart + _lookAhead, more);
+ final n = _readBuf(_window, _strStart + _lookAhead, more);
_lookAhead += n;
// Initialize the hash value now that we have some input:
@@ -873,7 +870,7 @@
// This function does not perform lazy evaluation of matches and inserts
// strings in the dictionary only for unmatched strings or for short
// matches. It is used only for the fast compression options.
- Future<int> _deflateFast(FlushMode flush) async {
+ int _deflateFast(FlushMode flush) {
var hashHead = 0; // head of the hash chain
bool bflush = false; // set if current block must be flushed
@@ -883,7 +880,7 @@
// for the next match, plus MIN_MATCH bytes to insert the
// string following the next match.
if (_lookAhead < minLookAhead) {
- await _fillWindow();
+ _fillWindow();
if (_lookAhead < minLookAhead && flush == FlushMode.none) {
return needMore;
}
@@ -963,11 +960,11 @@
}
if (bflush) {
- await _flushBlockOnly(false);
+ _flushBlockOnly(false);
}
}
- await _flushBlockOnly(flush == FlushMode.finish);
+ _flushBlockOnly(flush == FlushMode.finish);
return flush == FlushMode.finish ? finishDone : blockDone;
}
@@ -975,7 +972,7 @@
/// Same as above, but achieves better compression. We use a lazy
/// evaluation for matches: a match is finally adopted only if there is
/// no better match at the next window position.
- Future<int> _deflateSlow(FlushMode flush) async {
+ int _deflateSlow(FlushMode flush) {
var hashHead = 0; // head of hash chain
bool bflush = false; // set if current block must be flushed
@@ -986,7 +983,7 @@
// for the next match, plus MIN_MATCH bytes to insert the
// string following the next match.
if (_lookAhead < minLookAhead) {
- await _fillWindow();
+ _fillWindow();
if (_lookAhead < minLookAhead && flush == FlushMode.none) {
return needMore;
@@ -1066,7 +1063,7 @@
_strStart++;
if (bflush) {
- await _flushBlockOnly(false);
+ _flushBlockOnly(false);
}
} else if (_matchAvailable != 0) {
// If there was no match at the previous position, output a
@@ -1076,7 +1073,7 @@
bflush = _trTally(0, _window[_strStart - 1] & 0xff);
if (bflush) {
- await _flushBlockOnly(false);
+ _flushBlockOnly(false);
}
_strStart++;
_lookAhead--;
@@ -1093,7 +1090,7 @@
bflush = _trTally(0, _window[_strStart - 1] & 0xff);
_matchAvailable = 0;
}
- await _flushBlockOnly(flush == FlushMode.finish);
+ _flushBlockOnly(flush == FlushMode.finish);
return flush == FlushMode.finish ? finishDone : blockDone;
}
@@ -1192,18 +1189,18 @@
/// allocating a large strm->next_in buffer and copying from it.
/// (See also flush_pending()).
int total = 0;
- Future<int> _readBuf(Uint8List buf, int start, int size) async {
+ int _readBuf(Uint8List buf, int start, int size) {
if (size == 0 || input.isEOS) {
return 0;
}
- final data = await input.readBytes(size);
+ final data = input.readBytes(size);
var len = data.length;
if (len == 0) {
return 0;
}
- final bytes = await data.toUint8List();
+ final bytes = data.toUint8List();
if (len > bytes.length) {
len = bytes.length;
}
@@ -1217,9 +1214,9 @@
/// Flush as much pending output as possible. All deflate() output goes
/// through this function so some applications may wish to modify it
/// to avoid allocating a large strm->next_out buffer and copying into it.
- Future<void> _flushPending() async {
+ void _flushPending() {
final len = _pending;
- await output.writeBytes(_pendingBuffer, length: len);
+ output.writeBytes(_pendingBuffer, length: len);
_pendingOut += len;
_pending -= len;
diff --git a/lib/src/codecs/zlib/inflate.dart b/lib/src/codecs/zlib/inflate.dart
index 7ed0998..c50a151 100644
--- a/lib/src/codecs/zlib/inflate.dart
+++ b/lib/src/codecs/zlib/inflate.dart
@@ -1,4 +1,3 @@
-import 'dart:async';
import 'dart:typed_data';
import '../../util/input_stream.dart';
@@ -23,16 +22,15 @@
inputSet = true;
}
- Future<void> streamInput(Uint8List bytes) async {
+ void streamInput(Uint8List bytes) {
if (inputSet && input is InputStreamMemory) {
- final i = input as InputStreamMemory
- ..setPosition(_blockPos);
+ final i = input as InputStreamMemory..setPosition(_blockPos);
final inputLen = input.length;
final newLen = inputLen + bytes.length;
final newBytes = Uint8List(newLen)
- ..setRange(0, inputLen, i.buffer, i.position)
- ..setRange(inputLen, newLen, bytes, 0);
+ ..setRange(0, inputLen, i.buffer, i.position)
+ ..setRange(inputLen, newLen, bytes, 0);
input = InputStreamMemory(newBytes);
} else {
@@ -41,7 +39,7 @@
inputSet = true;
}
- Future<Uint8List?> inflateNext() async {
+ Uint8List? inflateNext() {
_bitBuffer = 0;
_bitBufferLen = 0;
if (output is OutputStreamMemory) {
@@ -70,9 +68,9 @@
}
/// Get the decompressed data.
- FutureOr<Uint8List> getBytes() => output.getBytes();
+ Uint8List getBytes() => output.getBytes();
- Future<void> inflate() async {
+ void inflate() {
_bitBuffer = 0;
_bitBufferLen = 0;
if (!inputSet) {
@@ -80,7 +78,7 @@
}
while (!input.isEOS) {
- if (!await _parseBlock()) {
+ if (!_parseBlock()) {
break;
}
}
@@ -88,13 +86,13 @@
/// Parse deflated block. Returns true if there is more to read, false
/// if we're done.
- Future<bool> _parseBlock() async {
+ bool _parseBlock() {
if (input.isEOS) {
return false;
}
// Each block has a 3-bit header
- final blockHeader = await _readBits(3);
+ final blockHeader = _readBits(3);
// BFINAL (is this the final block)?
final finalBlock = (blockHeader & 0x1) != 0;
@@ -103,17 +101,17 @@
final blockType = blockHeader >> 1;
switch (blockType) {
case 0: // Uncompressed block
- if (await _parseUncompressedBlock() == -1) {
+ if (_parseUncompressedBlock() == -1) {
return false;
}
break;
case 1: // Fixed huffman block
- if (await _parseFixedHuffmanBlock() == -1) {
+ if (_parseFixedHuffmanBlock() == -1) {
return false;
}
break;
case 2: // Dynamic huffman block
- if (await _parseDynamicHuffmanBlock() == -1) {
+ if (_parseDynamicHuffmanBlock() == -1) {
return false;
}
break;
@@ -126,7 +124,7 @@
}
/// Read a number of bits from the input stream.
- Future<int> _readBits(int length) async {
+ int _readBits(int length) {
if (length == 0) {
return 0;
}
@@ -138,7 +136,7 @@
}
// input byte
- final octet = await input.readByte();
+ final octet = input.readByte();
// concat octet
_bitBuffer |= octet << _bitBufferLen;
@@ -154,7 +152,7 @@
}
/// Read huffman code using [table].
- Future<int> _readCodeByTable(HuffmanTable table) async {
+ int _readCodeByTable(HuffmanTable table) {
final codeTable = table.table;
final maxCodeLength = table.maxCodeLength;
@@ -164,7 +162,7 @@
return -1;
}
- final octet = await input.readByte();
+ final octet = input.readByte();
_bitBuffer |= octet << _bitBufferLen;
_bitBufferLen += 8;
@@ -180,13 +178,13 @@
return codeWithLength & 0xffff;
}
- Future<int> _parseUncompressedBlock() async {
+ int _parseUncompressedBlock() {
// skip buffered header bits
_bitBuffer = 0;
_bitBufferLen = 0;
- final len = await _readBits(16);
- final nlen = await _readBits(16) ^ 0xffff;
+ final len = _readBits(16);
+ final nlen = _readBits(16) ^ 0xffff;
// Make sure the block size checksum is valid.
if (len != 0 && len != nlen) {
@@ -198,16 +196,16 @@
return -1;
}
- await output.writeStream(await input.readBytes(len));
+ output.writeStream(input.readBytes(len));
return 0;
}
- Future<int> _parseFixedHuffmanBlock() =>
+ int _parseFixedHuffmanBlock() =>
_decodeHuffman(_fixedLiteralLengthTable, _fixedDistanceTable);
- Future<int> _parseDynamicHuffmanBlock() async {
+ int _parseDynamicHuffmanBlock() {
// number of literal and length codes.
- var numLitLengthCodes = await _readBits(5);
+ var numLitLengthCodes = _readBits(5);
if (numLitLengthCodes == -1) {
return -1;
}
@@ -216,7 +214,7 @@
return -1;
}
// number of distance codes.
- var numDistanceCodes = await _readBits(5);
+ var numDistanceCodes = _readBits(5);
if (numDistanceCodes == -1) {
return -1;
}
@@ -225,7 +223,7 @@
return -1;
}
// number of code lengths.
- var numCodeLengths = await _readBits(4);
+ var numCodeLengths = _readBits(4);
if (numCodeLengths == -1) {
return -1;
}
@@ -237,7 +235,7 @@
// decode code lengths
final codeLengths = Uint8List(_order.length);
for (var i = 0; i < numCodeLengths; ++i) {
- final len = await _readBits(3);
+ final len = _readBits(3);
if (len == -1) {
return -1;
}
@@ -256,7 +254,7 @@
final distLengths = Uint8List.view(
litLenDistLengths.buffer, numLitLengthCodes, numDistanceCodes);
- if (await _decode(
+ if (_decode(
litLenDistLengths.length, codeLengthsTable, litLenDistLengths) ==
-1) {
return -1;
@@ -266,9 +264,9 @@
HuffmanTable(litlenLengths), HuffmanTable(distLengths));
}
- Future<int> _decodeHuffman(HuffmanTable litLen, HuffmanTable dist) async {
+ int _decodeHuffman(HuffmanTable litLen, HuffmanTable dist) {
while (true) {
- final code = await _readCodeByTable(litLen);
+ final code = _readCodeByTable(litLen);
if (code < 0 || code > 285) {
return -1;
}
@@ -280,7 +278,7 @@
// [0, 255] - Literal
if (code < 256) {
- await output.writeByte(code & 0xff);
+ output.writeByte(code & 0xff);
continue;
}
@@ -288,53 +286,50 @@
// length code
final ti = code - 257;
- var codeLength =
- _lengthCodeTable[ti] + await _readBits(_lengthExtraTable[ti]);
+ var codeLength = _lengthCodeTable[ti] + _readBits(_lengthExtraTable[ti]);
// distance code
- final distCode = await _readCodeByTable(dist);
+ final distCode = _readCodeByTable(dist);
if (distCode < 0 || distCode > 29) {
return -1;
}
final distance =
- _distCodeTable[distCode] + await _readBits(_distExtraTable[distCode]);
+ _distCodeTable[distCode] + _readBits(_distExtraTable[distCode]);
// lz77 decode
while (codeLength > distance) {
- await output.writeBytes(await output.subset(-distance));
+ output.writeBytes(output.subset(-distance));
codeLength -= distance;
}
if (codeLength == distance) {
- await output.writeBytes(await output.subset(-distance));
+ output.writeBytes(output.subset(-distance));
} else {
- final bytes =
- await output.subset(-distance, end: codeLength - distance);
- await output.writeBytes(bytes);
+ final bytes = output.subset(-distance, end: codeLength - distance);
+ output.writeBytes(bytes);
}
}
while (_bitBufferLen >= 8) {
_bitBufferLen -= 8;
- await input.rewind();
+ input.rewind();
}
return 0;
}
- Future<int> _decode(
- int num, HuffmanTable table, Uint8List codeLengths) async {
+ int _decode(int num, HuffmanTable table, Uint8List codeLengths) {
var prev = 0;
var i = 0;
while (i < num) {
- final code = await _readCodeByTable(table);
+ final code = _readCodeByTable(table);
if (code == -1) {
return -1;
}
switch (code) {
case 16:
// Repeat last code
- var repeat = await _readBits(2);
+ var repeat = _readBits(2);
if (repeat == -1) {
return -1;
}
@@ -345,7 +340,7 @@
break;
case 17:
// Repeat 0
- var repeat = await _readBits(3);
+ var repeat = _readBits(3);
if (repeat == -1) {
return -1;
}
@@ -357,7 +352,7 @@
break;
case 18:
// Repeat lots of 0s.
- var repeat = await _readBits(7);
+ var repeat = _readBits(7);
if (repeat == -1) {
return -1;
}
diff --git a/lib/src/codecs/zlib/zlib_decoder_base.dart b/lib/src/codecs/zlib/zlib_decoder_base.dart
index 2c0fae9..feaad39 100644
--- a/lib/src/codecs/zlib/zlib_decoder_base.dart
+++ b/lib/src/codecs/zlib/zlib_decoder_base.dart
@@ -6,7 +6,7 @@
abstract class ZLibDecoderBase {
const ZLibDecoderBase();
- Future<Uint8List> decodeBytes(Uint8List data, {bool verify = false});
+ Uint8List decodeBytes(Uint8List data, {bool verify = false});
- Future<Uint8List> decodeStream(InputStream input, {bool verify = false});
+ Uint8List decodeStream(InputStream input, {bool verify = false});
}
diff --git a/lib/src/codecs/zlib_decoder.dart b/lib/src/codecs/zlib_decoder.dart
index c1b3a42..70be2ce 100644
--- a/lib/src/codecs/zlib_decoder.dart
+++ b/lib/src/codecs/zlib_decoder.dart
@@ -7,9 +7,9 @@
class ZLibDecoder {
const ZLibDecoder();
- Future<Uint8List> decodeBytes(Uint8List data, {bool verify = false}) =>
+ Uint8List decodeBytes(Uint8List data, {bool verify = false}) =>
platformZLibDecoder.decodeBytes(data, verify: verify);
- Future<Uint8List> decodeStream(InputStream input, {bool verify = false}) =>
+ Uint8List decodeStream(InputStream input, {bool verify = false}) =>
platformZLibDecoder.decodeStream(input, verify: verify);
}
diff --git a/lib/src/codecs/zlib_encoder.dart b/lib/src/codecs/zlib_encoder.dart
index d80c9fe..e60affb 100644
--- a/lib/src/codecs/zlib_encoder.dart
+++ b/lib/src/codecs/zlib_encoder.dart
@@ -13,15 +13,15 @@
const ZLibEncoder();
- Future<Uint8List> encodeBytes(Uint8List bytes,
- {int level = CompressionLevel.defaultCompression}) async {
+ Uint8List encodeBytes(Uint8List bytes,
+ {int level = CompressionLevel.defaultCompression}) {
final output = OutputStreamMemory(byteOrder: ByteOrder.bigEndian);
- await encodeStream(InputStreamMemory(bytes), output, level: level);
+ encodeStream(InputStreamMemory(bytes), output, level: level);
return output.getBytes();
}
- Future<void> encodeStream(InputStream input, OutputStream output,
- {int level = CompressionLevel.defaultCompression}) async {
+ void encodeStream(InputStream input, OutputStream output,
+ {int level = CompressionLevel.defaultCompression}) {
output.byteOrder = ByteOrder.bigEndian;
// Compression Method and Flags
@@ -29,7 +29,7 @@
const cinfo = 7; //2^(7+8) = 32768 window size
const cmf = (cinfo << 4) | cm;
- await output.writeByte(cmf);
+ output.writeByte(cmf);
// 0x01, (00 0 00001) (FLG)
// bits 0 to 4 FCHECK (check bits for CMF and FLG)
@@ -45,18 +45,17 @@
fcheck++;
}
flag |= fcheck;
- await output.writeByte(flag);
+ output.writeByte(flag);
final startPos = input.position;
- final adler32 = await getAdler32Stream(input);
+ final adler32 = getAdler32Stream(input);
- await input.setPosition(startPos);
+ input.setPosition(startPos);
- final deflate = Deflate.stream(input, level: level, output: output);
- await deflate.deflate();
+ Deflate.stream(input, level: level, output: output)
+ .deflate();
- await output.writeUint32(adler32);
-
- await output.flush();
+ output..writeUint32(adler32)
+ ..flush();
}
}
diff --git a/lib/src/util/_file_handle.dart b/lib/src/util/_file_handle.dart
index 47db59f..65a19bb 100644
--- a/lib/src/util/_file_handle.dart
+++ b/lib/src/util/_file_handle.dart
@@ -16,11 +16,11 @@
bool get isOpen => false;
- Future<void> setPosition(int p) async {}
+ void setPosition(int p) {}
- Future<bool> open() async { return false; }
+ bool open() => false;
- Future<void> close() async {}
+ void close() {}
- Future<int> readInto(Uint8List buffer, [int? end]) async => 0;
+ int readInto(Uint8List buffer, [int? end]) => 0;
}
diff --git a/lib/src/util/_file_handle_io.dart b/lib/src/util/_file_handle_io.dart
index 0052efc..d1f7522 100644
--- a/lib/src/util/_file_handle_io.dart
+++ b/lib/src/util/_file_handle_io.dart
@@ -8,15 +8,15 @@
int _length;
FileHandle(this._path)
- : _position = 0
- , _length = 0;
+ : _position = 0,
+ _length = 0;
- Future<bool> open() async {
+ bool open() {
if (_file != null) {
return true;
}
- _file = await File(_path).open();
- _length = await _file?.length() ?? 0;
+ _file = File(_path).openSync();
+ _length = _file?.lengthSync() ?? 0;
_position = 0;
return _file != null;
}
@@ -29,29 +29,29 @@
bool get isOpen => _file != null;
- Future<void> setPosition(int p) async {
+ void setPosition(int p) {
if (_file == null || p == _position) {
return;
}
_position = p;
- await _file!.setPosition(p);
+ _file!.setPositionSync(p);
}
- Future<void> close() async {
+ void close() {
if (_file == null) {
return;
}
final fp = _file;
_file = null;
_position = 0;
- await fp!.close();
+ fp!.closeSync();
}
- Future<int> readInto(Uint8List buffer, [int? end]) async {
+ int readInto(Uint8List buffer, [int? end]) {
if (_file == null) {
- await open();
+ open();
}
- final size = await _file!.readInto(buffer, 0, end);
+ final size = _file!.readIntoSync(buffer, 0, end);
_position += size;
return size;
}
diff --git a/lib/src/util/adler32.dart b/lib/src/util/adler32.dart
index 47f42b0..9c40de0 100644
--- a/lib/src/util/adler32.dart
+++ b/lib/src/util/adler32.dart
@@ -4,7 +4,7 @@
import 'input_stream.dart';
-Future<int> getAdler32Stream(InputStream stream, [int adler = 1]) async {
+int getAdler32Stream(InputStream stream, [int adler = 1]) {
// largest prime smaller than 65536
const base = 65521;
@@ -18,7 +18,7 @@
}
len -= n;
while (--n >= 0) {
- s1 = s1 + await stream.readByte();
+ s1 = s1 + stream.readByte();
s2 = s2 + s1;
}
s1 %= base;
diff --git a/lib/src/util/file_content.dart b/lib/src/util/file_content.dart
index b5d6e6c..8b3115c 100644
--- a/lib/src/util/file_content.dart
+++ b/lib/src/util/file_content.dart
@@ -5,18 +5,18 @@
import 'output_stream.dart';
abstract class FileContent {
- Future<InputStream> getStream();
+ InputStream getStream();
- Future<void> write(OutputStream output);
+ void write(OutputStream output);
- Future<void> close();
+ void close();
- Future<Uint8List> readBytes() async {
- final stream = await getStream();
+ Uint8List readBytes() {
+ final stream = getStream();
return stream.toUint8List();
}
- Future<void> decompress(OutputStream output) async {}
+ void decompress(OutputStream output) {}
}
class FileContentMemory extends FileContent {
@@ -25,13 +25,13 @@
FileContentMemory(this.bytes);
@override
- Future<InputStream> getStream() async => InputStreamMemory(bytes);
+ InputStream getStream() => InputStreamMemory(bytes);
@override
- Future<void> write(OutputStream output) async => output.writeBytes(bytes);
+ void write(OutputStream output) => output.writeBytes(bytes);
@override
- Future<void> close() async {}
+ void close() {}
}
class FileContentStream extends FileContent {
@@ -40,11 +40,11 @@
FileContentStream(this.stream);
@override
- Future<InputStream> getStream() async => stream;
+ InputStream getStream() => stream;
@override
- Future<void> write(OutputStream output) async => output.writeStream(stream);
+ void write(OutputStream output) => output.writeStream(stream);
@override
- Future<void> close() async => stream.close();
+ void close() => stream.close();
}
diff --git a/lib/src/util/input_stream.dart b/lib/src/util/input_stream.dart
index e3f7811..d9e5301 100644
--- a/lib/src/util/input_stream.dart
+++ b/lib/src/util/input_stream.dart
@@ -1,4 +1,4 @@
-import 'dart:async';
+//import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
@@ -20,25 +20,25 @@
InputStream({required this.byteOrder});
- Future<bool> open();
+ bool open();
/// Asynchronously closes the input stream.
- Future<void> close();
+ void close();
/// Reset to the beginning of the stream.
- Future<void> reset();
+ void reset();
- Future<void> setPosition(int v);
+ void setPosition(int v);
/// Rewind the read head of the stream by the given number of bytes.
- Future<void> rewind([int length = 1]);
+ void rewind([int length = 1]);
/// Move the read position by [length] bytes.
- Future<void> skip(int length);
+ void skip(int length);
/// Read [count] bytes from an [offset] of the current read position, without
/// moving the read position.
- Future<InputStream> peekBytes(int count, {int offset = 0}) =>
+ InputStream peekBytes(int count, {int offset = 0}) =>
subset(position: position + offset, length: count);
/// Return a InputStream to read a subset of this stream. It does not
@@ -46,18 +46,18 @@
/// to the start of the buffer. If [position] is not specified, the current
/// read position is used. If [length] is not specified, the remainder of this
/// stream is used.
- Future<InputStream> subset({int? position, int? length});
+ InputStream subset({int? position, int? length});
/// Read a single byte.
- Future<int> readByte();
+ int readByte();
/// Read a single byte.
- Future<int> readUint8() => readByte();
+ int readUint8() => readByte();
/// Read a 16-bit word from the stream.
- Future<int> readUint16() async {
- final b1 = await readByte();
- final b2 = await readByte();
+ int readUint16() {
+ final b1 = readByte();
+ final b2 = readByte();
if (byteOrder == ByteOrder.bigEndian) {
return (b1 << 8) | b2;
}
@@ -65,10 +65,10 @@
}
/// Read a 24-bit word from the stream.
- Future<int> readUint24() async {
- final b1 = await readByte();
- final b2 = await readByte();
- final b3 = await readByte();
+ int readUint24() {
+ final b1 = readByte();
+ final b2 = readByte();
+ final b3 = readByte();
if (byteOrder == ByteOrder.bigEndian) {
return b3 | (b2 << 8) | (b1 << 16);
}
@@ -76,11 +76,11 @@
}
/// Read a 32-bit word from the stream.
- Future<int> readUint32() async {
- final b1 = await readByte();
- final b2 = await readByte();
- final b3 = await readByte();
- final b4 = await readByte();
+ int readUint32() {
+ final b1 = readByte();
+ final b2 = readByte();
+ final b3 = readByte();
+ final b4 = readByte();
if (byteOrder == ByteOrder.bigEndian) {
return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
}
@@ -88,15 +88,15 @@
}
/// Read a 64-bit word form the stream.
- Future<int> readUint64() async {
- final b1 = await readByte();
- final b2 = await readByte();
- final b3 = await readByte();
- final b4 = await readByte();
- final b5 = await readByte();
- final b6 = await readByte();
- final b7 = await readByte();
- final b8 = await readByte();
+ int readUint64() {
+ final b1 = readByte();
+ final b2 = readByte();
+ final b3 = readByte();
+ final b4 = readByte();
+ final b5 = readByte();
+ final b6 = readByte();
+ final b7 = readByte();
+ final b8 = readByte();
if (byteOrder == ByteOrder.bigEndian) {
return (b1 << 56) |
(b2 << 48) |
@@ -118,15 +118,15 @@
}
/// Read [count] bytes from the stream.
- Future<InputStream> readBytes(int count) async {
- final bytes = await subset(position: position, length: count);
- await setPosition(position + bytes.length);
+ InputStream readBytes(int count) {
+ final bytes = subset(position: position, length: count);
+ setPosition(position + bytes.length);
return bytes;
}
/// Read a null-terminated string, or if [size] is provided, that number of
/// bytes returned as a string.
- Future<String> readString({int? size, bool utf8 = true}) async {
+ String readString({int? size, bool utf8 = true}) {
String codesToString(List<int> codes) {
try {
final str = utf8
@@ -146,7 +146,7 @@
return '';
}
while (!isEOS) {
- final c = await readByte();
+ final c = readByte();
if (c == 0) {
return codesToString(codes);
}
@@ -155,11 +155,11 @@
throw ArchiveException('EOF reached without finding string terminator');
}
- final s = await readBytes(size);
- final codes = await s.toUint8List();
+ final s = readBytes(size);
+ final codes = s.toUint8List();
return codesToString(codes);
}
/// Convert the remaining bytes to a Uint8List.
- Future<Uint8List> toUint8List();
+ Uint8List toUint8List();
}
diff --git a/lib/src/util/input_stream_file.dart b/lib/src/util/input_stream_file.dart
index a93ddaa..6b872e4 100644
--- a/lib/src/util/input_stream_file.dart
+++ b/lib/src/util/input_stream_file.dart
@@ -36,15 +36,15 @@
super(byteOrder: other.byteOrder);
@override
- Future<bool> open() async {
- await _file.open();
+ bool open() {
+ _file.open();
_fileSize = _file.length;
return _file.isOpen;
}
@override
- Future<void> close() async {
- await _file.close();
+ void close() {
+ _file.close();
_fileSize = 0;
_position = 0;
_buffer = null;
@@ -68,25 +68,25 @@
int get fileRemaining => _fileSize - _position;
@override
- Future<void> setPosition(int v) async {
+ void setPosition(int v) {
if (v == _position) {
return;
}
if (v < _position) {
- await rewind(_position - v);
+ rewind(_position - v);
} else if (v > _position) {
- await skip(v - _position);
+ skip(v - _position);
}
}
@override
- Future<void> reset() async {
+ void reset() {
_position = 0;
return _readBuffer();
}
@override
- Future<void> skip(int length) async {
+ void skip(int length) {
if (_buffer == null) {
_position += length;
_position = _position.clamp(0, _fileSize);
@@ -98,16 +98,16 @@
_position += length;
} else {
_position += length;
- await _readBuffer();
+ _readBuffer();
}
}
@override
- Future<InputStream> subset({int? position, int? length}) async =>
+ InputStream subset({int? position, int? length}) =>
InputStreamFile.from(this, position: position, length: length);
@override
- Future<void> rewind([int length = 1]) async {
+ void rewind([int length = 1]) {
if (_buffer == null) {
_position -= length;
_position = _position.clamp(0, _fileSize);
@@ -116,7 +116,7 @@
if ((_bufferPosition - length) < 0) {
_position = max(_position - length, 0);
- await _readBuffer();
+ _readBuffer();
return;
}
_bufferPosition -= length;
@@ -124,13 +124,13 @@
}
@override
- Future<int> readByte() async {
+ int readByte() {
if (isEOS) {
return 0;
}
if (_buffer == null || _bufferPosition >= _bufferSize) {
- await _readBuffer();
+ _readBuffer();
}
if (_bufferPosition >= _bufferSize) {
@@ -142,16 +142,16 @@
}
@override
- Future<InputStream> readBytes(int count) async {
+ InputStream readBytes(int count) {
count = min(count, fileRemaining);
final bytes =
InputStreamFile.from(this, position: _position, length: count);
- await skip(count);
+ skip(count);
return bytes;
}
@override
- Future<Uint8List> toUint8List() async {
+ Uint8List toUint8List() {
if (isEOS) {
return Uint8List(0);
}
@@ -159,10 +159,10 @@
final length = fileRemaining;
final bytes = Uint8List(length);
- await _file.setPosition(_fileOffset + _position);
- final readBytes = await _file.readInto(bytes);
+ _file.setPosition(_fileOffset + _position);
+ final readBytes = _file.readInto(bytes);
- await skip(length);
+ skip(length);
if (readBytes != bytes.length) {
bytes.length = readBytes;
}
@@ -170,11 +170,11 @@
return bytes;
}
- Future<void> _readBuffer() async {
+ void _readBuffer() {
_bufferPosition = 0;
_buffer ??= Uint8List(min(_bufferSize, _fileSize));
- await _file.setPosition(_fileOffset + _position);
- _bufferSize = await _file.readInto(_buffer!, _buffer!.length);
+ _file.setPosition(_fileOffset + _position);
+ _bufferSize = _file.readInto(_buffer!, _buffer!.length);
}
}
diff --git a/lib/src/util/input_stream_memory.dart b/lib/src/util/input_stream_memory.dart
index 9868871..e89eb51 100644
--- a/lib/src/util/input_stream_memory.dart
+++ b/lib/src/util/input_stream_memory.dart
@@ -1,4 +1,4 @@
-import 'dart:async';
+//import 'dart:async';
import 'dart:typed_data';
import 'byte_order.dart';
@@ -57,34 +57,34 @@
bool get isEOS => _position >= _length;
@override
- Future<void> setPosition(int v) async {
+ void setPosition(int v) {
_position = v;
}
/// Reset to the beginning of the stream.
@override
- Future<void> reset() async {
+ void reset() {
_position = 0;
}
@override
- Future<bool> open() async => true;
+ bool open() => true;
@override
- Future<void> close() async {
+ void close() {
_position = 0;
}
/// Rewind the read head of the stream by the given number of bytes.
@override
- Future<void> rewind([int length = 1]) async {
+ void rewind([int length = 1]) {
_position -= length;
_position = _position.clamp(0, _length);
}
/// Move the read position by [count] bytes.
@override
- Future<void> skip(int count) async {
+ void skip(int count) {
_position += count;
_position = _position.clamp(0, _length);
}
@@ -98,7 +98,7 @@
/// read position is used. If [length] is not specified, the remainder of this
/// stream is used.
@override
- Future<InputStream> subset({int? position, int? length}) async {
+ InputStream subset({int? position, int? length}) {
position ??= _position;
length ??= _length - position;
return InputStreamMemory(buffer,
@@ -107,20 +107,20 @@
/// Read a single byte.
@override
- Future<int> readByte() async {
+ int readByte() {
final b = buffer[_position++];
return b;
}
@override
- Future<Uint8List> toUint8List() async {
+ Uint8List toUint8List() {
var len = length;
if ((_position + len) > buffer.length) {
len = buffer.length - _position;
}
final bytes =
- Uint8List.view(buffer.buffer, buffer.offsetInBytes + _position, len);
+ Uint8List.view(buffer.buffer, buffer.offsetInBytes + _position, len);
return bytes;
}
diff --git a/lib/src/util/output_stream.dart b/lib/src/util/output_stream.dart
index a26a78d..1844701 100644
--- a/lib/src/util/output_stream.dart
+++ b/lib/src/util/output_stream.dart
@@ -1,4 +1,4 @@
-import 'dart:async';
+//import 'dart:async';
import 'dart:typed_data';
import 'byte_order.dart';
@@ -11,53 +11,53 @@
OutputStream({required this.byteOrder});
- FutureOr<void> open() async {}
+ void open() {}
- FutureOr<void> close() async {}
+ void close() {}
bool get isOpen => true;
- FutureOr<void> clear();
+ void clear();
/// Write any pending data writes to the output.
- FutureOr<void> flush();
+ void flush();
/// Write a byte to the output stream.
- FutureOr<void> writeByte(int value);
+ void writeByte(int value);
/// Write a set of bytes to the output stream.
- FutureOr<void> writeBytes(Uint8List bytes, {int? length});
+ void writeBytes(Uint8List bytes, {int? length});
/// Write an InputStream to the output stream.
- FutureOr<void> writeStream(InputStream stream);
+ void writeStream(InputStream stream);
/// Write a 16-bit word to the output stream.
- Future<void> writeUint16(int value) async {
+ void writeUint16(int value) {
if (byteOrder == ByteOrder.bigEndian) {
- await writeByte((value >> 8) & 0xff);
- await writeByte(value & 0xff);
+ writeByte((value >> 8) & 0xff);
+ writeByte(value & 0xff);
} else {
- await writeByte(value & 0xff);
- await writeByte((value >> 8) & 0xff);
+ writeByte(value & 0xff);
+ writeByte((value >> 8) & 0xff);
}
}
/// Write a 32-bit word to the end of the buffer.
- Future<void> writeUint32(int value) async {
+ void writeUint32(int value) {
if (byteOrder == ByteOrder.bigEndian) {
- await writeByte((value >> 24) & 0xff);
- await writeByte((value >> 16) & 0xff);
- await writeByte((value >> 8) & 0xff);
- await writeByte(value & 0xff);
+ writeByte((value >> 24) & 0xff);
+ writeByte((value >> 16) & 0xff);
+ writeByte((value >> 8) & 0xff);
+ writeByte(value & 0xff);
} else {
- await writeByte(value & 0xff);
- await writeByte((value >> 8) & 0xff);
- await writeByte((value >> 16) & 0xff);
- await writeByte((value >> 24) & 0xff);
+ writeByte(value & 0xff);
+ writeByte((value >> 8) & 0xff);
+ writeByte((value >> 16) & 0xff);
+ writeByte((value >> 24) & 0xff);
}
}
- FutureOr<Uint8List> subset(int start, {int? end});
+ Uint8List subset(int start, {int? end});
- FutureOr<Uint8List> getBytes() async => subset(0, end: length);
+ Uint8List getBytes() => subset(0, end: length);
}
diff --git a/lib/src/util/output_stream_file.dart b/lib/src/util/output_stream_file.dart
index c774d83..4648dd9 100644
--- a/lib/src/util/output_stream_file.dart
+++ b/lib/src/util/output_stream_file.dart
@@ -21,18 +21,18 @@
int get length => _length;
@override
- Future<void> open() async {
- final file = await File(path).create(recursive: true);
- _fp = await file.open(mode: FileMode.write);
+ void open() {
+ final file = File(path)..createSync(recursive: true);
+ _fp = file.openSync(mode: FileMode.write);
}
@override
- Future<void> close() async {
+ void close() {
if (_fp == null) {
return;
}
- await flush();
- await _fp?.close();
+ flush();
+ _fp?.closeSync();
_fp = null;
}
@@ -40,15 +40,15 @@
bool get isOpen => _fp != null;
@override
- Future<void> clear() async {
+ void clear() {
_length = 0;
- await _fp?.setPosition(0);
+ _fp?.setPositionSync(0);
}
@override
- Future<void> flush() async {
+ void flush() {
if (_bufferPosition > 0 && _buffer != null) {
- await _fp?.writeFrom(_buffer!, 0, _bufferPosition);
+ _fp?.writeFromSync(_buffer!, 0, _bufferPosition);
_bufferPosition = 0;
}
}
@@ -63,28 +63,28 @@
/// Write a byte to the end of the buffer.
@override
- Future<void> writeByte(int value) async {
+ void writeByte(int value) {
if (!isOpen) {
throw ArchiveException('OutputStreamFile is not open');
}
final b = _getBuffer();
b[_bufferPosition++] = value;
if (_bufferPosition == b.length) {
- await flush();
+ flush();
}
_length++;
}
/// Write a set of bytes to the end of the buffer.
@override
- Future<void> writeBytes(Uint8List bytes, {int? length}) async {
+ void writeBytes(Uint8List bytes, {int? length}) {
if (!isOpen) {
throw ArchiveException('OutputStreamFile is not open');
}
final b = _getBuffer();
length ??= bytes.length;
if (_bufferPosition + length >= b.length) {
- await flush();
+ flush();
if (_bufferPosition + length < b.length) {
for (var i = 0, j = _bufferPosition; i < length; ++i, ++j) {
@@ -96,13 +96,13 @@
}
}
- await flush();
- await _fp!.writeFrom(bytes, 0, length);
+ flush();
+ _fp!.writeFromSync(bytes, 0, length);
_length += length;
}
@override
- Future<void> writeStream(InputStream stream) async {
+ void writeStream(InputStream stream) {
if (!isOpen) {
throw ArchiveException('OutputStreamFile is not open');
}
@@ -111,7 +111,7 @@
final len = stream.length;
if (_bufferPosition + len >= b.length) {
- await flush();
+ flush();
if (_bufferPosition + len < b.length) {
for (var i = 0, j = _bufferPosition, k = stream.position;
@@ -126,27 +126,27 @@
}
if (_bufferPosition > 0) {
- await flush();
+ flush();
}
- await _fp!.writeFrom(
+ _fp!.writeFromSync(
stream.buffer, stream.position, stream.position + stream.length);
_length += stream.length;
} else {
- final bytes = await stream.toUint8List();
- await writeBytes(bytes);
+ final bytes = stream.toUint8List();
+ writeBytes(bytes);
}
}
@override
- Future<Uint8List> subset(int start, {int? end}) async {
+ Uint8List subset(int start, {int? end}) {
if (!isOpen) {
throw ArchiveException('OutputStreamFile is not open');
}
if (_bufferPosition > 0) {
- await flush();
+ flush();
}
final fp = _fp!;
- final pos = await fp.position();
+ final pos = fp.positionSync();
if (start < 0) {
start = pos + start;
}
@@ -157,11 +157,11 @@
end = pos + end;
}
length = end - start;
- //final flen = fp.lengthSync();
- await fp.setPosition(start);
final buffer = Uint8List(length);
- await fp.readInto(buffer);
- await fp.setPosition(pos);
+ fp
+ ..setPositionSync(start)
+ ..readIntoSync(buffer)
+ ..setPositionSync(pos);
return buffer;
}
}
diff --git a/lib/src/util/output_stream_memory.dart b/lib/src/util/output_stream_memory.dart
index 9a009d6..aff992a 100644
--- a/lib/src/util/output_stream_memory.dart
+++ b/lib/src/util/output_stream_memory.dart
@@ -14,13 +14,13 @@
/// Create a byte buffer for writing.
OutputStreamMemory(
{int? size = defaultBufferSize,
- ByteOrder byteOrder = ByteOrder.littleEndian})
- : _buffer = Uint8List(size ?? defaultBufferSize)
- , length = 0
- , super(byteOrder: byteOrder);
+ ByteOrder byteOrder = ByteOrder.littleEndian})
+ : _buffer = Uint8List(size ?? defaultBufferSize),
+ length = 0,
+ super(byteOrder: byteOrder);
@override
- void flush() {}
+ void flush() {}
/// Get the resulting bytes from the buffer.
@override
@@ -29,7 +29,7 @@
/// Clear the buffer.
@override
- void clear() {
+ void clear() {
_buffer.length = defaultBufferSize;
length = 0;
}
@@ -41,7 +41,7 @@
/// Write a byte to the end of the buffer.
@override
- void writeByte(int value) {
+ void writeByte(int value) {
if (length == _buffer.length) {
_expandBuffer();
}
@@ -50,7 +50,7 @@
/// Write a set of bytes to the end of the buffer.
@override
- void writeBytes(Uint8List bytes, {int? length}) {
+ void writeBytes(Uint8List bytes, {int? length}) {
length ??= bytes.length;
while (this.length + length > _buffer.length) {
@@ -61,7 +61,7 @@
}
@override
- Future<void> writeStream(InputStream stream) async {
+ void writeStream(InputStream stream) {
while (length + stream.length > _buffer.length) {
_expandBuffer((length + stream.length) - _buffer.length);
}
@@ -70,7 +70,7 @@
_buffer.setRange(
length, length + stream.length, stream.buffer, stream.position);
} else {
- final bytes = await stream.toUint8List();
+ final bytes = stream.toUint8List();
_buffer.setRange(length, length + stream.length, bytes, 0);
}
length += stream.length;
@@ -107,7 +107,7 @@
}
final newLength = (_buffer.length + blockSize) * 2;
final newBuffer = Uint8List(newLength)
- ..setRange(0, _buffer.length, _buffer);
+ ..setRange(0, _buffer.length, _buffer);
_buffer = newBuffer;
}
}
diff --git a/test/input_stream_file_test.dart b/test/input_stream_file_test.dart
index 3c5649c..5ea03ad 100644
--- a/test/input_stream_file_test.dart
+++ b/test/input_stream_file_test.dart
@@ -18,20 +18,18 @@
group('InputStreamFile', () {
test('length', () async {
- final fs = InputStreamFile(testPath);
- await fs.open();
+ final fs = InputStreamFile(testPath)..open();
expect(fs.length, testData.length);
});
test('readBytes', () async {
- final input = InputStreamFile(testPath);
- await input.open();
+ final input = InputStreamFile(testPath)..open();
expect(input.length, equals(120));
var same = true;
var ai = 0;
while (!input.isEOS) {
- final bs = await input.readBytes(50);
- final bytes = await bs.toUint8List();
+ final bs = input.readBytes(50);
+ final bytes = bs.toUint8List();
for (var i = 0; i < bytes.length; ++i) {
same = bytes[i] == ai + i;
if (!same) {
@@ -44,11 +42,11 @@
});
test('position', () async {
- final fs = InputStreamFile(testPath, bufferSize: 2);
- await fs.open();
- await fs.setPosition(50);
- final bs = await fs.readBytes(50);
- final b = await bs.toUint8List();
+ final fs = InputStreamFile(testPath, bufferSize: 2)
+ ..open()
+ ..setPosition(50);
+ final bs = fs.readBytes(50);
+ final b = bs.toUint8List();
expect(b.length, 50);
for (var i = 0; i < b.length; ++i) {
expect(b[i], testData[50 + i]);
@@ -56,11 +54,11 @@
});
test('skip', () async {
- final fs = InputStreamFile(testPath, bufferSize: 2);
- await fs.open();
- await fs.skip(50);
- final bs = await fs.readBytes(50);
- final b = await bs.toUint8List();
+ final fs = InputStreamFile(testPath, bufferSize: 2)
+ ..open()
+ ..skip(50);
+ final bs = fs.readBytes(50);
+ final b = bs.toUint8List();
expect(b.length, 50);
for (var i = 0; i < b.length; ++i) {
expect(b[i], testData[50 + i]);
@@ -68,12 +66,12 @@
});
test('rewind', () async {
- final fs = InputStreamFile(testPath, bufferSize: 2);
- await fs.open();
- await fs.skip(50);
- await fs.rewind(10);
- final bs = await fs.readBytes(50);
- final b = await bs.toUint8List();
+ final fs = InputStreamFile(testPath, bufferSize: 2)
+ ..open()
+ ..skip(50)
+ ..rewind(10);
+ final bs = fs.readBytes(50);
+ final b = bs.toUint8List();
expect(b.length, 50);
for (var i = 0; i < b.length; ++i) {
expect(b[i], testData[40 + i]);
@@ -81,10 +79,10 @@
});
test('peakBytes', () async {
- final fs = InputStreamFile(testPath, bufferSize: 2);
- await fs.open();
- final bs = await fs.peekBytes(10);
- final b = await bs.toUint8List();
+ final fs = InputStreamFile(testPath, bufferSize: 2)
+ ..open();
+ final bs = fs.peekBytes(10);
+ final b = bs.toUint8List();
expect(fs.position, 0);
expect(b.length, 10);
for (var i = 0; i < b.length; ++i) {
@@ -93,11 +91,11 @@
});
test("clone", () async {
- final input = InputStreamFile(testPath);
- await input.open();
+ final input = InputStreamFile(testPath)
+ ..open();
final input2 = InputStreamFile.from(input, position: 6, length: 5);
- final bs = await input2.readBytes(5);
- final b = await bs.toUint8List();
+ final bs = input2.readBytes(5);
+ final b = bs.toUint8List();
expect(b.length, 5);
for (var i = 0; i < b.length; ++i) {
expect(b[i], testData[6 + i]);
diff --git a/test/input_stream_memory_test.dart b/test/input_stream_memory_test.dart
index d619e6c..560847d 100644
--- a/test/input_stream_memory_test.dart
+++ b/test/input_stream_memory_test.dart
@@ -13,22 +13,22 @@
const data = [0xaa, 0xbb, 0xcc];
final input = InputStreamMemory.fromList(data);
expect(input.length, equals(3));
- expect(await input.readByte(), equals(0xaa));
- expect(await input.readByte(), equals(0xbb));
- expect(await input.readByte(), equals(0xcc));
+ expect(input.readByte(), equals(0xaa));
+ expect(input.readByte(), equals(0xbb));
+ expect(input.readByte(), equals(0xcc));
expect(input.isEOS, equals(true));
});
test('peakBytes', () async {
const data = [0xaa, 0xbb, 0xcc];
final input = InputStreamMemory.fromList(data);
- expect(await input.readByte(), equals(0xaa));
+ expect(input.readByte(), equals(0xaa));
- final bytes = await (await input.peekBytes(2)).toUint8List();
+ final bytes = input.peekBytes(2).toUint8List();
expect(bytes[0], equals(0xbb));
expect(bytes[1], equals(0xcc));
- expect(await input.readByte(), equals(0xbb));
- expect(await input.readByte(), equals(0xcc));
+ expect(input.readByte(), equals(0xbb));
+ expect(input.readByte(), equals(0xcc));
expect(input.isEOS, equals(true));
});
@@ -36,9 +36,9 @@
const data = [0xaa, 0xbb, 0xcc];
final input = InputStreamMemory.fromList(data);
expect(input.length, equals(3));
- expect(await input.readByte(), equals(0xaa));
- await input.skip(1);
- expect(await input.readByte(), equals(0xcc));
+ expect(input.readByte(), equals(0xaa));
+ input.skip(1);
+ expect(input.readByte(), equals(0xcc));
expect(input.isEOS, equals(true));
});
@@ -46,46 +46,46 @@
const data = [0xaa, 0xbb, 0xcc, 0xdd, 0xee];
final input = InputStreamMemory.fromList(data);
expect(input.length, equals(5));
- expect(await input.readByte(), equals(0xaa));
+ expect(input.readByte(), equals(0xaa));
- final i2 = await input.subset(length: 3);
+ final i2 = input.subset(length: 3);
- final i3 = await i2.subset(position: 1, length: 2);
+ final i3 = i2.subset(position: 1, length: 2);
- expect(await i2.readByte(), equals(0xbb));
- expect(await i2.readByte(), equals(0xcc));
- expect(await i2.readByte(), equals(0xdd));
+ expect(i2.readByte(), equals(0xbb));
+ expect(i2.readByte(), equals(0xcc));
+ expect(i2.readByte(), equals(0xdd));
expect(i2.isEOS, equals(true));
- expect(await i3.readByte(), equals(0xcc));
- expect(await i3.readByte(), equals(0xdd));
+ expect(i3.readByte(), equals(0xcc));
+ expect(i3.readByte(), equals(0xdd));
});
test('readString', () async {
const data = [84, 101, 115, 116, 0];
final input = InputStreamMemory.fromList(data);
- var s = await input.readString();
+ var s = input.readString();
expect(s, equals('Test'));
expect(input.isEOS, equals(true));
- await input.reset();
+ input.reset();
- s = await input.readString(size: 4);
+ s = input.readString(size: 4);
expect(s, equals('Test'));
- expect(await input.readByte(), equals(0));
+ expect(input.readByte(), equals(0));
expect(input.isEOS, equals(true));
});
test('readBytes', () async {
const data = [84, 101, 115, 116, 0];
final input = InputStreamMemory.fromList(data);
- final b = await (await input.readBytes(3)).toUint8List();
+ final b = input.readBytes(3).toUint8List();
expect(b.length, equals(3));
expect(b[0], equals(84));
expect(b[1], equals(101));
expect(b[2], equals(115));
- expect(await input.readByte(), equals(116));
- expect(await input.readByte(), equals(0));
+ expect(input.readByte(), equals(116));
+ expect(input.readByte(), equals(0));
expect(input.isEOS, equals(true));
});
@@ -93,48 +93,48 @@
const data = [0xaa, 0xbb, 0xcc, 0xdd, 0xee];
// Little endian (by default)
final input = InputStreamMemory.fromList(data);
- expect(await input.readUint16(), equals(0xbbaa));
+ expect(input.readUint16(), equals(0xbbaa));
// Big endian
final i2 = InputStreamMemory.fromList(
data, byteOrder: ByteOrder.bigEndian);
- expect(await i2.readUint16(), equals(0xaabb));
+ expect(i2.readUint16(), equals(0xaabb));
});
test('readUint24', () async {
const data = [0xaa, 0xbb, 0xcc, 0xdd, 0xee];
// Little endian (by default)
final input = InputStreamMemory.fromList(data);
- expect(await input.readUint24(), equals(0xccbbaa));
+ expect(input.readUint24(), equals(0xccbbaa));
// Big endian
final i2 = InputStreamMemory.fromList(
data, byteOrder: ByteOrder.bigEndian);
- expect(await i2.readUint24(), equals(0xaabbcc));
+ expect(i2.readUint24(), equals(0xaabbcc));
});
test('readUint32', () async {
const data = [0xaa, 0xbb, 0xcc, 0xdd, 0xee];
// Little endian (by default)
final input = InputStreamMemory.fromList(data);
- expect(await input.readUint32(), equals(0xddccbbaa));
+ expect(input.readUint32(), equals(0xddccbbaa));
// Big endian
final i2 = InputStreamMemory.fromList(
data, byteOrder: ByteOrder.bigEndian);
- expect(await i2.readUint32(), equals(0xaabbccdd));
+ expect(i2.readUint32(), equals(0xaabbccdd));
});
test('readUint64', () async {
const data = [0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0xee, 0xdd];
// Little endian (by default)
final input = InputStreamMemory.fromList(data);
- expect(await input.readUint64(), equals(0xddeeffeeddccbbaa));
+ expect(input.readUint64(), equals(0xddeeffeeddccbbaa));
// Big endian
final i2 = InputStreamMemory.fromList(
data, byteOrder: ByteOrder.bigEndian);
- expect(await i2.readUint64(), equals(0xaabbccddeeffeedd));
+ expect(i2.readUint64(), equals(0xaabbccddeeffeedd));
});
});
}
diff --git a/test/output_stream_file_test.dart b/test/output_stream_file_test.dart
index 51331a9..7b6d9d9 100644
--- a/test/output_stream_file_test.dart
+++ b/test/output_stream_file_test.dart
@@ -8,18 +8,18 @@
void main() {
group('OutputStreamFile', () {
test('InputStreamFile/OutputStreamFile', () async {
- final input = InputStreamFile('test/_data/folder.zip');
- await input.open();
- final output = OutputStreamFile('$testOutputPath/folder.zip');
- await output.open();
+ final input = InputStreamFile('test/_data/folder.zip')
+ ..open();
+ final output = OutputStreamFile('$testOutputPath/folder.zip')
+ ..open();
while (!input.isEOS) {
- final bytes = await input.readBytes(50);
- await output.writeStream(bytes);
+ final bytes = input.readBytes(50);
+ output.writeStream(bytes);
}
- await input.close();
- await output.close();
+ input.close();
+ output.close();
final aBytes = File('test/_data/folder.zip').readAsBytesSync();
final bBytes = File('$testOutputPath/folder.zip').readAsBytesSync();
@@ -32,18 +32,18 @@
test('InputStreamMemory/OutputStreamFile', () async {
final bytes = List<int>.generate(256, (index) => index);
- final input = InputStreamMemory.fromList(bytes);
- await input.open();
- final output = OutputStreamFile('$testOutputPath/test.bin');
- await output.open();
+ final input = InputStreamMemory.fromList(bytes)
+ ..open();
+ final output = OutputStreamFile('$testOutputPath/test.bin')
+ ..open();
while (!input.isEOS) {
- final bytes = await input.readBytes(50);
- await output.writeStream(bytes);
+ final bytes = input.readBytes(50);
+ output.writeStream(bytes);
}
- await input.close();
- await output.close();
+ input.close();
+ output.close();
final aBytes = File('$testOutputPath/test.bin').readAsBytesSync();
@@ -54,17 +54,17 @@
});
test('InputStreamFile/OutputStreamMemory', () async {
- final input = InputStreamFile('test/_data/folder.zip');
- await input.open();
- final output = OutputStreamMemory();
- await output.open();
+ final input = InputStreamFile('test/_data/folder.zip')
+ ..open();
+ final output = OutputStreamMemory()
+ ..open();
while (!input.isEOS) {
- final bytes = await input.readBytes(50);
- await output.writeStream(bytes);
+ final bytes = input.readBytes(50);
+ output.writeStream(bytes);
}
- await input.close();
+ input.close();
final aBytes = File('test/_data/folder.zip').readAsBytesSync();
final bBytes = output.getBytes();
diff --git a/test/output_stream_memory_test.dart b/test/output_stream_memory_test.dart
index f30b3e0..6eadeb3 100644
--- a/test/output_stream_memory_test.dart
+++ b/test/output_stream_memory_test.dart
@@ -26,7 +26,7 @@
const len = 0xffff;
for (var i = 0; i < len; ++i) {
- await out.writeUint16(i);
+ out.writeUint16(i);
}
final bytes = out.getBytes();
@@ -34,7 +34,7 @@
final input = InputStreamMemory(bytes);
for (var i = 0; i < len; ++i) {
- final x = await input.readUint16();
+ final x = input.readUint16();
expect(x, equals(i));
}
});
@@ -44,7 +44,7 @@
const len = 0xffff;
for (var i = 0; i < len; ++i) {
- await out.writeUint32(0xffff + i);
+ out.writeUint32(0xffff + i);
}
final bytes = out.getBytes();
@@ -52,7 +52,7 @@
final input = InputStreamMemory(bytes);
for (var i = 0; i < len; ++i) {
- final x = await input.readUint32();
+ final x = input.readUint32();
expect(x, equals(0xffff + i));
}
});
diff --git a/test/zip_test.dart b/test/zip_test.dart
index 9609558..e3adb0f 100644
--- a/test/zip_test.dart
+++ b/test/zip_test.dart
@@ -14,13 +14,12 @@
await extractArchiveToDisk(e, root);
} else {
final f = e as ArchiveFile;
- //final output = OutputStreamFile(path);
- //await output.open();
- //await f.writeContent(output);
- final bytes = await f.readBytes();
+ final output = OutputStreamFile(path)
+ ..open();
+ f.writeContent(output);
+ final bytes = f.readBytes();
expect(bytes, isNotNull);
expect(bytes!.length, greaterThan(0));
- //print('${f.fullPathName}: ${bytes?.length} ${f.isCompressed}');
}
}
}
@@ -28,10 +27,13 @@
void main() async {
group('Zip', () {
test('decode', () async {
- final archive = await ZipDecoder().decodeStream(
+ final archive = ZipDecoder().decodeStream(
InputStreamMemory(File('test/_data/zip/android-javadoc.zip').readAsBytesSync()));
+ final t1 = Stopwatch()..start();
await extractArchiveToDisk(archive, '$testOutputPath/android-javadoc');
+ t1.stop();
+ //print(t1.elapsedMilliseconds);
});
});
}
diff --git a/test/zlib_test.dart b/test/zlib_test.dart
index 5ccef12..3cdacd8 100644
--- a/test/zlib_test.dart
+++ b/test/zlib_test.dart
@@ -13,8 +13,8 @@
group('ZLib', () {
test('encode/decode', () async {
- final compressed = await const ZLibEncoder().encodeBytes(buffer);
- final decompressed = await const ZLibDecoder().decodeBytes(compressed,
+ final compressed = const ZLibEncoder().encodeBytes(buffer);
+ final decompressed = const ZLibDecoder().decodeBytes(compressed,
verify: true);
expect(decompressed.length, equals(buffer.length));
for (var i = 0; i < buffer.length; ++i) {
@@ -24,16 +24,16 @@
test('encodeStream', () async {
{
- final outStream = OutputStreamFile('$testOutputPath/zlib_stream.zlib');
- await outStream.open();
+ final outStream = OutputStreamFile('$testOutputPath/zlib_stream.zlib')
+ ..open();
final inStream = InputStreamMemory(buffer);
- await const ZLibEncoder().encodeStream(inStream, outStream);
+ const ZLibEncoder().encodeStream(inStream, outStream);
}
{
- final inStream = InputStreamFile('$testOutputPath/zlib_stream.zlib');
- await inStream.open();
- final decoded = await const ZLibDecoder().decodeStream(inStream);
+ final inStream = InputStreamFile('$testOutputPath/zlib_stream.zlib')
+ ..open();
+ final decoded = const ZLibDecoder().decodeStream(inStream);
expect(decoded.length, equals(buffer.length));
for (var i = 0; i < buffer.length; ++i) {