Ejemplo n.º 1
0
        protected override void _Unir(string fichero, string dirDest)
        {
            SplitterMergerInfo info = SplitterMergerInfo.GetInfoFromFile (fichero);
            if (info != null)
            {
                if (info.Compression == SplitterMergerCompression.V3_COMPRESSION)
                {
                    throw new FormatNotSupportedException ("Compression in Splitter&Merger 3.0 is not supported");
                }

                Stream fos = UtilidadesFicheros.CreateWriter (dirDest + Path.DirectorySeparatorChar + info.OriginalFileName);
                ChecksumStream validator = null;
                if (info.ValidateCrc)
                {
                    validator = new ChecksumStream (fos, new Crc32 ());
                    fos = validator;
                }
                Stream smInput = new SplitterMergerStream (info);
                Stream input = smInput;
                if (info.Compression == SplitterMergerCompression.GZIP_COMPRESSION)
                {
                    input = new GZipStream (input, CompressionMode.Decompress);
                }
                byte[] buffer = new byte[Consts.BUFFER_LENGTH];
                int leidos = 0;
                while ((leidos = input.Read (buffer, 0, buffer.Length)) > 0)
                {
                    fos.Write (buffer, 0, leidos);
                    OnProgress(smInput.Position, info.Length);
                }
                fos.Close ();
                if (info.ValidateCrc)
                {
                    if (validator.Crc.Value != info.Crc)
                    {
                        throw new ChecksumVerificationException ("Checksum verification failed", fichero);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int leidos = 0;
            if (dataStream == null)
            {
                leidos = inputStream.Read (tmpBuffer, 0, 3);
                this.Count (leidos);
                if (leidos != 3)
                {
                    return 0;
                }
                StringBuilder sb = new StringBuilder ();
                for (int i = 0; i < 3; i++)
                {
                    sb.Append ((char)tmpBuffer[i]);
                }
                string it = sb.ToString ();
                if (!it.Equals ("SDT") && !it.Equals ("FDA"))
                {
                    throw new IOException ("Unexpected file start tag:[" + it + "]");
                }
                this.currentBlock = ReadBlockHeader ();
                this.currentBlockNumber = 1;
                crc.Reset ();

                dataStream = new ChecksumStream (new SizeLimiterStream (inputStream, currentBlock.Size), crc);
            }
            leidos = dataStream.Read (buffer, offset, count);
            this.Count (leidos);
            // Se termina el bloque
            if (leidos < count) {
                if (this.crc.Value != this.currentBlock.Crc)
                {
                    throw new IOException ("Invalid checksum " + this.currentEntry.Name + ":" + this.currentBlockNumber);
                }
                if (this.currentBlockNumber == this.currentEntry.NumBlocks)
                {
                    return leidos;
                }
                this.currentBlock = ReadBlockHeader ();
                this.currentBlockNumber++;
                crc.Reset ();
                dataStream =  new ChecksumStream(new SizeLimiterStream (inputStream, currentBlock.Size), crc);
                return leidos + this.Read (buffer, offset + leidos, count - leidos);
            }
            return leidos;
        }