|
|
|
|
|
|
|
|
using System.IO; |
|
|
using System.Text; |
|
|
using SlobViewer.Common; |
|
|
|
|
|
namespace SlobViewer.Slob |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class StoreItemFileBased : StoreItemBase |
|
|
{ |
|
|
long _filePosition; |
|
|
|
|
|
|
|
|
public StoreItemFileBased(long filePosition) |
|
|
{ |
|
|
_filePosition = filePosition; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public StoreItemFileBased(byte[] contentIds, byte[] compressedContent) |
|
|
{ |
|
|
_contentIds = contentIds; |
|
|
_compressedContent = compressedContent; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public (string Content, int ContentId) GetAt(int idx, Stream stream, Encoding encoding, string compression, byte[] buffer) |
|
|
{ |
|
|
ReadCompressedContentFromStream(stream, buffer); |
|
|
|
|
|
|
|
|
|
|
|
if (null != _compressedContent) |
|
|
{ |
|
|
DecompressContent(encoding, compression, buffer); |
|
|
|
|
|
_compressedContent = null; |
|
|
} |
|
|
|
|
|
return (_content[idx], _contentIds[idx]); |
|
|
} |
|
|
|
|
|
|
|
|
private void StoreCompressedContentForDebugging() |
|
|
{ |
|
|
using (var s = new FileStream("C:\\TEMP\\CompressedContent.XXX", FileMode.Create, FileAccess.Write, FileShare.Read)) |
|
|
{ |
|
|
s.Write(_compressedContent, 0, _compressedContent.Length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void ReadCompressedContentFromStream(Stream stream, byte[] buffer) |
|
|
{ |
|
|
stream.Seek(_filePosition, SeekOrigin.Begin); |
|
|
stream.Read(buffer, 0, 4); |
|
|
uint count = BigEndianBitConverter.ToUInt32(buffer, 0); |
|
|
_contentIds = new byte[count]; |
|
|
for (int k = 0; k < count; ++k) |
|
|
{ |
|
|
_contentIds[k] = (byte)stream.ReadByte(); |
|
|
} |
|
|
|
|
|
stream.Read(buffer, 0, 4); |
|
|
uint contentLen = BigEndianBitConverter.ToUInt32(buffer, 0); |
|
|
_compressedContent = new byte[contentLen]; |
|
|
stream.Read(_compressedContent, 0, (int)contentLen); |
|
|
} |
|
|
} |
|
|
} |
|
|
|