protected override void WriteDataToStream(Stream stream, SharedExtractParams extractParams, bool decompress) { var reader = extractParams.Reader; decompress = decompress && this.Compressed; reader.BaseStream.Position = (long)Offset; // Reset at start since value might still be in used for a bit after this.BytesWritten = 0; if (this.Archive.Type == ArchiveTypes.BSA_SE) { // Separate Skyrim Special Edition extraction ulong filesz = this.Size & 0x3fffffff; if (this.Archive.ContainsFileNameBlobs) { int len = reader.ReadByte(); filesz -= (ulong)len + 1; reader.BaseStream.Seek((long)this.Offset + 1 + len, SeekOrigin.Begin); } uint filesize = (uint)filesz; if (this.Size > 0 && this.Compressed) { filesize = reader.ReadUInt32(); filesz -= 4; } if (!decompress) { StreamUtils.WriteSectionToStream(reader.BaseStream, filesz, stream, bytesWritten => this.BytesWritten = bytesWritten); } else { CompressionUtils.DecompressLZ4(reader.BaseStream, (uint)filesz, stream, bytesWritten => this.BytesWritten = bytesWritten); } } else { // Skip ahead if (this.Archive.ContainsFileNameBlobs) { reader.BaseStream.Position += reader.ReadByte() + 1; } if (!decompress) { StreamUtils.WriteSectionToStream(reader.BaseStream, this.Size, stream, bytesWritten => this.BytesWritten = bytesWritten); } else { if (this.Compressed) { reader.ReadUInt32(); // Skip } CompressionUtils.Decompress(reader.BaseStream, this.Size - 4, stream, bytesWriten => this.BytesWritten = bytesWriten, extractParams); } } }