private void InflateStream(string fileName) { // then we will get it fresh into local deflatedName // StreamOutput deflatedStream = new StreamOutput(CacheDirectory.CreateOutput(deflatedName)); using (var deflatedStream = new MemoryStream()) { // get the deflated blob _blob.DownloadToStream(deflatedStream); #if FULLDEBUG Trace.WriteLine($"GET {_name} RETREIVED {deflatedStream.Length} bytes"); #endif // seek back to begininng deflatedStream.Seek(0, SeekOrigin.Begin); // open output file for uncompressed contents using (var fileStream = new StreamOutput(CacheDirectory.CreateOutput(fileName))) using (var decompressor = new DeflateStream(deflatedStream, CompressionMode.Decompress)) { var bytes = new byte[65535]; var nRead = 0; do { nRead = decompressor.Read(bytes, 0, 65535); if (nRead > 0) { fileStream.Write(bytes, 0, nRead); } } while (nRead == 65535); } } }
/// <summary>. </summary> public void SyncFile(Lucene.Net.Store.Directory directory, string fileName, bool CompressBlobs) { Trace.WriteLine($"INFO Syncing file {fileName} for {_rootFolderName}"); // then we will get it fresh into local deflatedName // StreamOutput deflatedStream = new StreamOutput(CacheDirectory.CreateOutput(deflatedName)); // seek back to begininng if (ShouldCompressFile(fileName, CompressBlobs)) { using (var deflatedStream = new MemoryStream()) { #if FULLDEBUG Trace.WriteLine($"GET {fileName} RETREIVED {deflatedStream.Length} bytes"); #endif // get the deflated blob blob.DownloadTo(deflatedStream); deflatedStream.Seek(0, SeekOrigin.Begin); // open output file for uncompressed contents using (var fileStream = new StreamOutput(directory.CreateOutput(fileName))) using (var decompressor = new DeflateStream(deflatedStream, CompressionMode.Decompress)) { var bytes = new byte[65535]; var nRead = 0; do { nRead = decompressor.Read(bytes, 0, 65535); if (nRead > 0) { fileStream.Write(bytes, 0, nRead); } } while (nRead == 65535); } } } else { using (var fileStream = new StreamOutput(directory.CreateOutput(fileName))) { // get the blob blob.DownloadTo(fileStream); fileStream.Flush(); #if FULLDEBUG Trace.WriteLine($"GET {fileName} RETREIVED {fileStream.Length} bytes"); #endif } } }
/// <summary>. </summary> public bool SyncFile(Lucene.Net.Store.Directory directory, string fileName, bool CompressBlobs) { var success = false; try { var blob = _blobContainer.GetBlobClient(_rootFolderName + fileName); _loggingService.Log(new LogEntry(LogLevel.Info, null, $"Syncing file {fileName} for {_rootFolderName}")); // then we will get it fresh into local deflatedName // StreamOutput deflatedStream = new StreamOutput(CacheDirectory.CreateOutput(deflatedName)); using (var deflatedStream = new MemoryStream()) { // get the deflated blob blob.DownloadTo(deflatedStream); #if FULLDEBUG _loggingService.Log(new LogEntry(LogLevel.Info, null, $"GET {fileName} RETREIVED {deflatedStream.Length} bytes")); #endif // seek back to begininng deflatedStream.Seek(0, SeekOrigin.Begin); if (ShouldCompressFile(fileName, CompressBlobs)) { // open output file for uncompressed contents using (var fileStream = new StreamOutput(directory.CreateOutput(fileName))) using (var decompressor = new DeflateStream(deflatedStream, CompressionMode.Decompress)) { var bytes = new byte[65535]; var nRead = 0; do { nRead = decompressor.Read(bytes, 0, 65535); if (nRead > 0) { fileStream.Write(bytes, 0, nRead); } } while (nRead == 65535); } } else { using (var fileStream = new StreamOutput(directory.CreateOutput(fileName))) { // get the blob blob.DownloadTo(fileStream); fileStream.Flush(); #if FULLDEBUG _loggingService.Log(new LogEntry(LogLevel.Info, null, $"GET {fileName} RETREIVED {fileStream.Length} bytes")); #endif } } } success = true; } catch (Exception e) { _loggingService.Log(new LogEntry(LogLevel.Error, e, $"GET {fileName} RETREIVED failed")); } return(success); }