unrar5: unpack wip

This commit is contained in:
coderb
2017-12-20 14:22:47 -05:00
parent fd9790cc36
commit 91c85f0aa6
2 changed files with 13 additions and 3 deletions

View File

@@ -30,6 +30,15 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
}
}
private int UnpIO_UnpRead(byte[] buf, int offset, int count) {
// NOTE: caller has logic to check for -1 for error we throw instead.
return this.readStream.Read(buf, offset, count);
}
private void UnpIO_UnpWrite(byte[] buf, size_t offset, uint count) {
this.writeStream.Write(buf, checked((int)offset), checked((int)count));
}
public void DoUnpack(FileHeader fileHeader, Stream readStream, Stream writeStream)
{
// as of 12/2017 .NET limits array indexing to using a signed integer
@@ -95,6 +104,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
public static byte[] EnsureCapacity(byte[] array, int length) {
return array.Length < length ? new byte[length] : array;
}
}
}
#endif

View File

@@ -258,7 +258,7 @@ bool UnpReadBuf()
DataSize=ReadTop;
int ReadCode=0;
if (BitInput.MAX_SIZE!=DataSize)
ReadCode=UnpIO->UnpRead(Inp.InBuf+DataSize,BitInput.MAX_SIZE-DataSize);
ReadCode=UnpIO_UnpRead(Inp.InBuf,DataSize,BitInput.MAX_SIZE-DataSize);
if (ReadCode>0) // Can be also -1.
ReadTop+=ReadCode;
ReadBorder=ReadTop-30;
@@ -359,7 +359,7 @@ void UnpWriteBuf()
Filters[I].Type=FILTER_NONE;
if (OutMem!=null)
UnpIO->UnpWrite(OutMem,BlockLength);
UnpIO_UnpWrite(OutMem,0,BlockLength);
UnpSomeRead=true;
WrittenFileSize+=BlockLength;
@@ -549,7 +549,7 @@ void UnpWriteData(byte[] Data, size_t offset, size_t Size)
int64 LeftToWrite=DestUnpSize-WrittenFileSize;
if ((int64)WriteSize>LeftToWrite)
WriteSize=(size_t)LeftToWrite;
UnpIO->UnpWrite(Data, offset, WriteSize);
UnpIO_UnpWrite(Data, offset, WriteSize);
WrittenFileSize+=Size;
}