Ejemplo n.º 1
0
        protected override async Task CopyFromSource(ILogger log, CancellationToken token)
        {
            if (await _blob.ExistsAsync())
            {
                log.LogInformation($"GET {_blob.Uri.AbsoluteUri}");

                if (File.Exists(LocalCacheFile.FullName))
                {
                    LocalCacheFile.Delete();
                }

                using (var cache = File.OpenWrite(LocalCacheFile.FullName))
                {
                    await _blob.DownloadToStreamAsync(cache);
                }

                // If the blob is compressed it needs to be decompressed locally before it can be used
                if (_blob.Properties.ContentEncoding?.Equals("gzip", StringComparison.OrdinalIgnoreCase) == true)
                {
                    log.LogInformation($"Decompressing {_blob.Uri.AbsoluteUri}");

                    var gzipFile = LocalCacheFile.FullName + ".gz";
                    File.Move(LocalCacheFile.FullName, gzipFile);

                    using (Stream destination = File.Create(LocalCacheFile.FullName))
                        using (Stream source = File.OpenRead(gzipFile))
                            using (Stream zipStream = new GZipStream(source, CompressionMode.Decompress))
                            {
                                zipStream.CopyTo(destination);
                            }
                }
            }
        }
Ejemplo n.º 2
0
        public Task Write(JObject json, ILogger log, CancellationToken token)
        {
            _downloaded = true;
            _hasChanges = true;

            if (File.Exists(LocalCacheFile.FullName))
            {
                LocalCacheFile.Delete();
            }

            JsonUtility.SaveJson(LocalCacheFile, json);

            return(Task.FromResult(true));
        }
Ejemplo n.º 3
0
        public Task Write(Stream stream, ILogger log, CancellationToken token)
        {
            _downloaded = true;
            _hasChanges = true;

            using (stream)
            {
                if (File.Exists(LocalCacheFile.FullName))
                {
                    LocalCacheFile.Delete();
                }

                using (var writeStream = File.OpenWrite(LocalCacheFile.FullName))
                {
                    stream.CopyTo(writeStream);
                    stream.Seek(0, SeekOrigin.Begin);
                }
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 4
0
        protected override async Task CopyFromSource(ILogger log, CancellationToken token)
        {
            Uri absoluteUri = UriUtility.GetPath(RootPath, key);

            if (!await FileExistsAsync(client, bucketName, key, token).ConfigureAwait(false))
            {
                return;
            }

            log.LogInformation($"GET {absoluteUri}");

            if (File.Exists(LocalCacheFile.FullName))
            {
                LocalCacheFile.Delete();
            }

            string contentEncoding;

            using (FileStream cache = File.OpenWrite(LocalCacheFile.FullName))
            {
                contentEncoding = await DownloadFileAsync(client, bucketName, key, cache, token).ConfigureAwait(false);
            }

            if (contentEncoding?.Equals("gzip", StringComparison.OrdinalIgnoreCase) == true)
            {
                log.LogInformation($"Decompressing {absoluteUri}");

                string gzipFile = LocalCacheFile.FullName + ".gz";
                File.Move(LocalCacheFile.FullName, gzipFile);

                using (Stream destination = File.Create(LocalCacheFile.FullName))
                    using (Stream source = File.OpenRead(gzipFile))
                        using (Stream zipStream = new GZipStream(source, CompressionMode.Decompress))
                        {
                            await zipStream.CopyToAsync(destination, DefaultCopyBufferSize, token).ConfigureAwait(false);
                        }
            }
        }