CopyToAsync() 공개 메소드

public CopyToAsync ( Stream destination, int bufferSize, CancellationToken cancellationToken ) : Task
destination Stream
bufferSize int
cancellationToken CancellationToken
리턴 Task
 public async Task<byte[]> BeforeDeserialization(IEnvelope envelope, byte[] serializedMessage)
 {
     using (var inputStream = new MemoryStream(serializedMessage))
     using (var decompressionStream = new GZipStream(inputStream, CompressionMode.Decompress))
     using (var outputStream = new MemoryStream())
     {
         await decompressionStream.CopyToAsync(outputStream).ConfigureAwait(false);
         return outputStream.ToArray();
     }
 }
 /// <inheritdoc />
 protected async override Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     using (content)
     {
         var compressedStream = await content.ReadAsStreamAsync();
         using (var uncompressedStream = new GZipStream(compressedStream, CompressionMode.Decompress))
         {
             await uncompressedStream.CopyToAsync(stream);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Asychronously Decompresses a string using System.IO.Compression.GZipStream
 /// </summary>
 /// <param name="s">String to decompress</param>
 /// <returns>Decompressed string</returns>
 public static async Task<string> DecompressAsync(string s)
 {
     var bytes = Convert.FromBase64String(s);
     using (var msi = new MemoryStream(bytes))
     using (var mso = new MemoryStream())
     {
         using (var gs = new GZipStream(msi, CompressionMode.Decompress))
         {
             await gs.CopyToAsync(mso);
         }
         return Encoding.Unicode.GetString(mso.ToArray());
     }
 }
        /// <summary>
        /// Downloads an xml file from AniDB which contains all of the titles for every anime, and their IDs,
        /// and saves it to disk.
        /// </summary>
        /// <param name="titlesFile">The destination file name.</param>
        private async Task DownloadTitles(string titlesFile)
        {
            _logger.Debug("Downloading new AniDB titles file.");

            var client = new WebClient();

            await AniDbSeriesProvider.RequestLimiter.Tick();

            using (var stream = await client.OpenReadTaskAsync(TitlesUrl))
            using (var unzipped = new GZipStream(stream, CompressionMode.Decompress))
            using (var writer = File.Open(titlesFile, FileMode.Create, FileAccess.Write))
            {
                await unzipped.CopyToAsync(writer).ConfigureAwait(false);
            }
        }
예제 #5
0
 public static async Task<string> DecompressAsync(string input)
 {
     using (var inputStream = new MemoryStream(Convert.FromBase64String(input)))
     {
         using (var stream = new GZipStream(inputStream, CompressionMode.Decompress))
         {
             using (var outputStream = new MemoryStream())
             {
                 await stream.CopyToAsync(outputStream);
                 var output = outputStream.ToArray();
                 return Encoding.UTF8.GetString(output, 0, output.Length);
             }
         }
     }
 }
예제 #6
0
 public static async Task WriteFlotAppAsync(Stream output, bool decompress = false)
 {
     if (!decompress)
     {
         using (var stream = Assembly.GetAssembly(typeof(FlotWebApp)).GetManifestResourceStream("Metrics.Visualization.index.full.html.gz"))
         {
             await stream.CopyToAsync(output).ConfigureAwait(false);
         }
     }
     else
     {
         using (var stream = Assembly.GetAssembly(typeof(FlotWebApp)).GetManifestResourceStream("Metrics.Visualization.index.full.html.gz"))
         using (var gzip = new GZipStream(stream, CompressionMode.Decompress))
         {
             await gzip.CopyToAsync(output).ConfigureAwait(false);
         }
     }
 }
예제 #7
0
        /// <summary>
        /// Decrompresses Given File
        /// </summary>
        /// <param name="File">File to Decompress</param>
        public static async Task<String> Decrompress(String file)
        {
            FileInfo Info = new FileInfo(file);
            string newFileName;

            using (FileStream originalFileStream = Info.OpenRead())
            {
                string currentFile = Info.FullName;
                 newFileName = currentFile.Remove(currentFile.Length - Info.Extension.Length);

                using (FileStream decompressed = File.Create(newFileName))
                {
                    using (GZipStream decompression = new GZipStream(originalFileStream, CompressionMode.Decompress))
                    {
                        await decompression.CopyToAsync(decompressed);
                    }
                }
            }

            Info.Delete();

            return newFileName;
        }
예제 #8
0
		/// <summary>
		/// takes byte array and decompress it into Content
		/// </summary>
		public async Task Decompress()
		{
			if (CompressedContent != null && CompressedContent.Length != 0)
			{
				using (MemoryStream inStream = new MemoryStream(CompressedContent))
				using (MemoryStream outStream = new MemoryStream())
				{
					using (GZipStream gz = new GZipStream(inStream, CompressionMode.Decompress))
					{
						await gz.CopyToAsync(outStream);
					}
					Content = Encoding.Unicode.GetString(outStream.ToArray());
				}
			}
			else
			{
				Content = "";
			}
		}
        /// <summary>
        /// Saves content of this attachment to a temp file.
        /// </summary>
        /// <returns></returns>
        public async Task<IStorageFile> SaveToFile()
        {
            var target = await ApplicationData.Current.TemporaryFolder
                .CreateFolderAsync("Attachments",
                    CreationCollisionOption.OpenIfExists);

            var file = await target.CreateFileAsync(Key,
                CreationCollisionOption.ReplaceExisting);

            var value = Value;
            var compressed = value.Attribute("Compressed");
            var isCompressed = compressed != null && (bool)compressed;


            if (!isCompressed)
            {
                var buffer = CryptographicBuffer
                    .DecodeFromBase64String(value.Value);
                await FileIO.WriteBufferAsync(file, buffer);
            }
            else
            {
                var bytes = Convert.FromBase64String(value.Value);

                using (var buffer = new MemoryStream(bytes))
                using (var gz = new GZipStream(buffer, CompressionMode.Decompress))
                using (var output = await file.OpenStreamForWriteAsync())
                {
                    await gz.CopyToAsync(output);
                }
            }

            return file;
        }