예제 #1
0
        static ConcatenatedStream ConcatenateStream(Stream l, Stream r)
        {
            var cstream = new ConcatenatedStream();

            cstream.pending_streams.Enqueue(l);
            cstream.pending_streams.Enqueue(r);

            cstream.length = l.Length + r.Length;

            return(cstream);
        }
예제 #2
0
        public static ConcatenatedStream operator +(ConcatenatedStream cs, IEnumerable <Stream> xs)
        {
            var cstream = new ConcatenatedStream();

            cstream.pending_streams.Enqueue(cs);
            cstream.length += cs.length;

            foreach (var x in xs)
            {
                cstream.pending_streams.Enqueue(x);
                cstream.length += x.Length;
            }

            return(cstream);
        }
예제 #3
0
        public ZipFile(IEnumerable <ZipEntry> entries)
        {
            this.entries = entries;

            var offset = 0L;

            foreach (var entry in entries)
            {
                offsets.Add(offset, entry);
                offset += entry.Length;
            }

            var main_entries = new ConcatenatedStream(from entry in entries select(Stream) entry);

            var central_directory = new List <Stream>();

            foreach (var entry in offsets)
            {
                FileHeaders

                         _offset                  = (little_endian)(int)entry.Key,
                         total_records            = (little_endian)entries.Count(),
                         made_by                  = (little_endian)(ushort)19,
                         version_needed           = ZipEntry.VERSION_NEEDED,
                         general                  = ZipEntry.GENERAL,
                         method                   = ZipEntry.COMPRESSION_METHOD,
                         last_mod_time            = entry.Value.last_mod_time,
                         last_mod_date            = entry.Value.last_mod_date,
                         crc32                    = entry.Value.crc32,
                         compressed_size          = entry.Value.compressed_size,
                         uncompressed_size        = entry.Value.uncompressed_size,
                         file_name_length         = entry.Value.file_name_length,
                         file_name_bytes          = new MemoryStream(entry.Value.file_name_bytes),
                         file_comment_length      = (little_endian)(ushort)0,
                         disk_where_file_starts   = (little_endian)(short)0,
                         internal_file_attributes = (little_endian)(short)0,
                         external_file_attributes = (little_endian)(int)0,
                         extra_field_length       = ZipEntry.EXTRA_FIELD_LENGTH,
                         zip64_id                 = entry.Value.zip64_id,
                         zip64_len                = entry.Value.zip64_len,
                         zip64_compressed         = entry.Value.zip64_compressed,
                         zip64_uncompressed       = entry.Value.zip64_uncompressed;

                ConcatenatedStream directory_entry =

                    new[]
                {
                    CENTRAL_DIRECTORY_FILE_HEADER_SIGNATURE,
                    made_by,
                    version_needed,
                    general,
                    method,
                    last_mod_time,
                    last_mod_date,
                    crc32,
                    compressed_size,
                    uncompressed_size,
                    file_name_length,
                    extra_field_length,
                    file_comment_length,
                    disk_where_file_starts,
                    internal_file_attributes,
                    external_file_attributes,
                    _offset,
                    file_name_bytes,
                    zip64_id,
                    zip64_len,
                    zip64_compressed,
                    zip64_uncompressed
                };

                central_directory.Add(directory_entry);
            }

            FileHeaders //ZIP64 END OF CENTRAL DIRECTORY

                zip_64_end_of_central_directory_signature     = ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE,
                size_of_zip64_end_of_central_directory_record = (little_endian)(ulong)44,
                version_made_by           = VERSION_MADE_BY,
                version_needed_to_extract = VERSION_NEEDED_TO_EXTRACT,
                number_of_this_disk_64    = (little_endian)(uint)0,
                number_of_the_disk_with_the_start_of_the_central_directory    = (little_endian)(uint)0,
                total_number_of_entries_in_the_central_directory_on_this_disk = (little_endian)(ulong)offsets.Count,
                total_number_of_entries_in_the_central_director = (little_endian)(ulong)offsets.Count,
                size_of_the_central_directory = (little_endian)(ulong)central_directory.Sum(x => x.Length),
                offset_of_start_of_central_directory_with_respect_to_the_starting_disk_number = (little_endian)(ulong)main_entries.Length;

            ConcatenatedStream

                zip64_end_of_central_directory =

                new[]
            {
                zip_64_end_of_central_directory_signature,
                size_of_zip64_end_of_central_directory_record,
                version_made_by,
                version_needed_to_extract,
                number_of_this_disk_64,
                number_of_the_disk_with_the_start_of_the_central_directory,
                total_number_of_entries_in_the_central_director,
                total_number_of_entries_in_the_central_directory_on_this_disk,
                size_of_zip64_end_of_central_directory_record,
                offset_of_start_of_central_directory_with_respect_to_the_starting_disk_number
            };


            FileHeaders

                zip64_end_of_central_dir_locator_signature = ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIGNATURE,
                number_of_the_disk_with_the_start_of_the_zip64_end_of_central_directory = (little_endian)(uint)0,
                relative_offset_of_the_zip64_end_of_central_directory_record
                = (little_endian)(ulong)((ulong)main_entries.Length + (ulong)(central_directory.Sum(x => x.Length))),
                total_number_of_disks = (little_endian)(uint)1;


            ConcatenatedStream

                zip64_end_of_central_directory_locator =

                new[]
            {
                zip64_end_of_central_dir_locator_signature,
                number_of_the_disk_with_the_start_of_the_zip64_end_of_central_directory,
                relative_offset_of_the_zip64_end_of_central_directory_record,
                total_number_of_disks
            };


            FileHeaders

                central_directory_length            = (little_endian)(int)central_directory.Sum(x => x.Length),
                number_of_this_disk                 = (little_endian)(ushort)0,
                disk_where_central_directory_starts = (little_endian)(ushort)0,
                number_of_central_directory_records_on_this_disk = (little_endian)(ushort)central_directory.Count,
                total_number_of_records           = (little_endian)(ushort)central_directory.Count,
                offset_start_of_central_directory = (little_endian)(int)main_entries.Length,
                comment_length = (little_endian)(ushort)0;


            ConcatenatedStream end_of_directory =

                new[]
            {
                END_OF_CENTRAL_DIRECTORY_SIGNATURE,
                number_of_this_disk,
                disk_where_central_directory_starts,
                number_of_central_directory_records_on_this_disk,
                total_number_of_records,
                central_directory_length,
                offset_start_of_central_directory,
                comment_length,
            };

            stream = main_entries + central_directory + zip64_end_of_central_directory + zip64_end_of_central_directory_locator + end_of_directory;
        }