public DownloadFile ( IDocument remoteDocument, Stream localFileStream, |
||
remoteDocument | IDocument | Remote document. |
localFileStream | Stream | Local taget file stream. |
transmission | Transmission status. | |
hashAlg | Hash algoritm, which should be used to calculate hash of the uploaded stream content | |
update | UpdateChecksum | Not or not yet used |
return | void |
public void DownloadFile(
IDocument remoteDocument,
Stream localFileStream,
Transmission transmission,
HashAlgorithm hashAlg,
UpdateChecksum update = null)
{
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = localFileStream.Read(buffer, 0, buffer.Length)) > 0) {
hashAlg.TransformBlock(buffer, 0, len, buffer, 0);
}
}
long? fileLength = remoteDocument.ContentStreamLength;
// Download content if exists
if (fileLength > 0) {
long offset = localFileStream.Position;
long remainingBytes = (fileLength != null) ? (long)fileLength - offset : this.ChunkSize;
try {
do {
offset += this.DownloadNextChunk(remoteDocument, offset, remainingBytes, transmission, localFileStream, hashAlg);
} while(fileLength == null);
} catch (DotCMIS.Exceptions.CmisConstraintException) {
}
} else {
transmission.Position = 0;
transmission.Length = 0;
}
hashAlg.TransformFinalBlock(new byte[0], 0, 0);
}
public void ResumeDownloadWithUtils() { long startPos = this.remoteLength / 2; SetupResumeDownload(startPos); using (var memorystream = new MemoryStream(this.remoteChunk)) { this.mockedStream.Setup(stream => stream.Stream).Returns(memorystream); using (IFileDownloader downloader = new ChunkedDownloader(this.chunkSize)) { ContentTaskUtils.PrepareResume(startPos, this.localFileStream, this.hashAlg); downloader.DownloadFile(this.mock.Object, this.localFileStream, this.transmission, this.hashAlg); Assert.AreEqual(this.remoteContent.Length, this.localFileStream.Length); Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.remoteContent), this.hashAlg.Hash); Assert.AreEqual(SHA1Managed.Create().ComputeHash(this.localFileStream.ToArray()), this.hashAlg.Hash); } } }