Ejemplo n.º 1
0
        public async Task AddFileToArchiveAsync(SourceFileInfo fileInfo, CancellationToken cancellationToken)
        {
            if (isClosed)
            {
                throw new InvalidOperationException("Archive has been closed");
            }

            var fileName = fileInfo.GetNameWithPath("/");

            var tarHeader = new TarHeader
            {
                Name    = fileName,
                Size    = fileInfo.Length,
                ModTime = fileInfo.LastModified ?? DateTime.UtcNow
            };

            Log.Debug(() => $"Adding {fileName} ({fileInfo.Length} bytes) to archive");

            var tarEntry = new TarEntry(tarHeader);

            this.tarOutputStream.PutNextEntry(tarEntry);

            using (var inputStream = await fileInfo.GetStreamAsync(cancellationToken))
            {
                if (inputStream != null && inputStream.Length > 0)
                {
                    await inputStream.CopyToAsync(tarOutputStream, 81920, cancellationToken);
                }
            }

            this.tarOutputStream.CloseEntry();
        }
Ejemplo n.º 2
0
        public async Task AddFileToArchiveAsync(SourceFileInfo fileInfo, CancellationToken cancellationToken)
        {
            var zipEntryName = fileInfo.GetNameWithPath("/");

            Log.Debug(() => $"Adding {zipEntryName} ({fileInfo.Length} bytes) to archive");

            var zipEntry = new ZipEntry(zipEntryName)
            {
                DateTime = fileInfo.LastModified ?? DateTime.UtcNow
            };

            this.zipOutputStream.PutNextEntry(zipEntry);

            using (var inputStream = await fileInfo.GetStreamAsync(cancellationToken))
            {
                if (inputStream != null && inputStream.Length > 0)
                {
                    await inputStream.CopyToAsync(zipOutputStream, 81920, cancellationToken);
                }
            }

            this.zipOutputStream.CloseEntry();
        }