Ejemplo n.º 1
0
        /// <summary>
        /// This method is used to chunk the file data.
        /// </summary>
        /// <returns>A list of LeafNodeObjectData.</returns>
        public override List <LeafNodeObject> Chunking()
        {
            int maxChunkSize           = 1 * 1024 * 1024;
            List <LeafNodeObject> list = new List <LeafNodeObject>();

            LeafNodeObject.IntermediateNodeObjectBuilder builder = new LeafNodeObject.IntermediateNodeObjectBuilder();
            int chunkStart = 0;

            if (this.FileContent.Length <= maxChunkSize)
            {
                list.Add(builder.Build(this.FileContent, this.GetSignature(this.FileContent)));

                return(list);
            }

            while (chunkStart < this.FileContent.Length)
            {
                int    chunkLength = chunkStart + maxChunkSize >= this.FileContent.Length ? this.FileContent.Length - chunkStart : maxChunkSize;
                byte[] temp        = AdapterHelper.GetBytes(this.FileContent, chunkStart, chunkLength);
                list.Add(builder.Build(temp, this.GetSignature(temp)));
                chunkStart += chunkLength;
            }

            return(list);
        }
        /// <summary>
        /// This method is used to chunk the file data.
        /// </summary>
        /// <returns>A list of LeafNodeObjectData.</returns>
        public override List <LeafNodeObject> Chunking()
        {
            List <LeafNodeObject> list = new List <LeafNodeObject>();

            LeafNodeObject.IntermediateNodeObjectBuilder builder = new LeafNodeObject.IntermediateNodeObjectBuilder();

            int index = 0;

            while (ZipHeader.IsFileHeader(this.FileContent, index))
            {
                byte[] dataFileSignatureBytes;
                byte[] header         = this.AnalyzeFileHeader(this.FileContent, index, out dataFileSignatureBytes);
                int    headerLength   = header.Length;
                int    compressedSize = (int)this.GetCompressedSize(dataFileSignatureBytes);

                if (headerLength + compressedSize <= 4096)
                {
                    list.Add(builder.Build(AdapterHelper.GetBytes(this.FileContent, index, headerLength + compressedSize), this.GetSingleChunkSignature(header, dataFileSignatureBytes)));
                    index += headerLength += compressedSize;
                }
                else
                {
                    list.Add(builder.Build(header, this.GetSHA1Signature(header)));
                    index += headerLength;

                    byte[] dataFile = AdapterHelper.GetBytes(this.FileContent, index, compressedSize);

                    if (dataFile.Length <= 1048576)
                    {
                        list.Add(builder.Build(dataFile, this.GetDataFileSignature(dataFileSignatureBytes)));
                    }
                    else
                    {
                        list.AddRange(this.GetSubChunkList(dataFile));
                    }

                    index += compressedSize;
                }
            }

            if (0 == index)
            {
                return(null);
            }

            byte[] final = AdapterHelper.GetBytes(this.FileContent, index, this.FileContent.Length - index);

            if (final.Length <= 1048576)
            {
                list.Add(builder.Build(final, this.GetSHA1Signature(final)));
            }
            else
            {
                // In current, it has no idea about how to compute the signature for final part larger than 1MB.
                throw new NotImplementedException("If the final chunk is larger than 1MB, the signature method is not implemented.");
            }

            return(list);
        }