mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-23 15:34:34 +00:00
Wrong flags set, we do not expose this in the interface
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@@ -98,10 +98,24 @@ namespace SharpCompress.Writers.Zip
|
||||
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // disk=0
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // file type: binary
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // Internal file attributes
|
||||
|
||||
// Internal file attributes:
|
||||
// Bit 0: apparent ASCII/ text file
|
||||
// Bit 1: reserved
|
||||
// Bit 2: control field records precede logical records
|
||||
// Bits 3 - 16: unused
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // file type: binary, Internal file attributes
|
||||
|
||||
// External flags are host-dependent, this might match DOS
|
||||
// Bit 0: Read-Only
|
||||
// Bit 1: Hidden
|
||||
// Bit 2: System
|
||||
// Bit 3: Label
|
||||
// Bit 4: Directory
|
||||
// Bit 5: Archive
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0);
|
||||
outputStream.Write(intBuf.Slice(0, 2)); // External file attributes
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0x8100);
|
||||
outputStream.Write(intBuf.Slice(0, 2));
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@ using System.Text;
|
||||
|
||||
using SharpCompress.Common;
|
||||
using Xunit;
|
||||
using System.IO;
|
||||
using SharpCompress.Writers.Zip;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
|
||||
namespace SharpCompress.Test.Zip
|
||||
{
|
||||
@@ -52,23 +49,5 @@ namespace SharpCompress.Test.Zip
|
||||
{
|
||||
Assert.Throws<InvalidFormatException>(() => Write(CompressionType.Rar, "Zip.ppmd.noEmptyDirs.zip", "Zip.ppmd.noEmptyDirs.zip"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Zip_Write_MemoryStream()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
var zw = new ZipWriter(ms, new ZipWriterOptions(compressionType: CompressionType.Deflate ) { DeflateCompressionLevel = CompressionLevel.None } );
|
||||
var payload = new string('\n', 100000);
|
||||
using (var stream = zw.WriteToStream("test.txt", new ZipWriterEntryOptions()))
|
||||
using (var streamWriter = new StreamWriter(stream: stream))
|
||||
{
|
||||
streamWriter.Write(payload);
|
||||
}
|
||||
|
||||
using( var file = new FileStream("d:\\projects\\test.zip", FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
ms.WriteTo(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user