AddStream() public méthode

Add full contents of a stream into the Zip storage
public AddStream ( Compression _method, string _filenameInZip, Stream _source, System.DateTime _modTime, string _comment ) : void
_method Compression /// Compression method ///
_filenameInZip string /// Filename and path as desired in Zip directory ///
_source Stream /// Stream object containing the data to store in Zip ///
_modTime System.DateTime /// Modification time of the data to store ///
_comment string /// Comment for stored file ///
Résultat void
Exemple #1
0
        // ToDo: PRIORITY TASK! This code needs more testing & condensation
        private void AddToZip(ZipStorer zipStorer, string basePath, string path, FileShare share)
        {
            path = Path.GetFullPath(path);

            // If this is not inside basePath, lets change the basePath so at least some directories are kept
            if (!path.StartsWith(basePath))
            {
                basePath = Path.GetDirectoryName(path);
            }

            if (Directory.Exists(path))
            {
                foreach (var file in Directory.GetFiles(path))
                {
                    this.AddToZip(zipStorer, basePath, file, share);
                }

                foreach (var dir in Directory.GetDirectories(path))
                {
                    this.AddToZip(zipStorer, basePath, dir, share);
                }
            }
            else if (File.Exists(path))
            {
                var nameInZip = path.Substring(basePath.Length);
                if (nameInZip.StartsWith("\\") || nameInZip.StartsWith("/"))
                {
                    nameInZip = nameInZip.Substring(1);
                }

                nameInZip = Path.Combine("files", nameInZip);

                using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare))
                {
                    zipStorer.AddStream(ZipStorer.Compression.Deflate, nameInZip, stream, File.GetLastWriteTime(path), string.Empty);
                }
            }
        }
Exemple #2
0
        // ToDo: PRIORITY TASK! This code needs more testing & condensation
        private void AddToZip(ZipStorer zipStorer, string basePath, string path, FileShare share)
        {
            path = Path.GetFullPath(path);

            // If this is not inside basePath, lets change the basePath so at least some directories are kept
            if (!path.StartsWith(basePath))
            {
                basePath = Path.GetDirectoryName(path);
            }

            if (Directory.Exists(path))
            {
                foreach (var file in Directory.GetFiles(path))
                {
                    this.AddToZip(zipStorer, basePath, file, share);
                }

                foreach (var dir in Directory.GetDirectories(path))
                {
                    this.AddToZip(zipStorer, basePath, dir, share);
                }
            }
            else if (File.Exists(path))
            {
                var nameInZip = path.Substring(basePath.Length);
                if (nameInZip.StartsWith("\\") || nameInZip.StartsWith("/"))
                {
                    nameInZip = nameInZip.Substring(1);
                }

                nameInZip = Path.Combine("files", nameInZip);

                using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare))
                {
                    zipStorer.AddStream(ZipStorer.Compression.Deflate, nameInZip, stream, File.GetLastWriteTime(path), string.Empty);
                }
            }
        }