Esempio n. 1
0
        //TODO addChildBlockFile et remplacer add childblock
        internal void addChildBlockFile(BlockType b)//child source est toujours le fichier FileNode
        {
            if (!CurrentNodeFile.CanWrite)
            {
                CreateNewChildFile();
            }
            if (Top.EncodingNeeded(depth) || IsCompressed())//on doit encoder ?
            {
                SetCompressed();
                b.GoStartIndex(FileSource);
                using (FileStream childCopy = MakeNodeFileTemp())
                {
                    FileSource.Seek(StartPosition + TotalSize, SeekOrigin.Begin);//on se met la ou on doit ajouter le block encodé
                    childCopy.Seek(0, SeekOrigin.Begin);
                    //childCopy.SetLength(b.TotalSize);

                    long start_pos = FileSource.Position;

                    Top.Encode(childCopy, CurrentNodeFile, b.TotalSize, -1);                                       //encodage de l'abre enfant dans son fichier

                    FileSource.Write(Encoding.ASCII.GetBytes(CurrentNodeFileName), 0, CurrentNodeFileName.Length); //ce n'est pas les nom des fichier qui sont encodé mais
                    BlockMarker(FileSource);
                    long compress_size = (FileSource.Position - start_pos);

                    addBlockSize(start_pos, compress_size, b.FrameInBlock, b.FirstFrame);//la taille à changé puisqu'on encode
                    Console.WriteLine("arbre (d=" + Depth + ") contenant les frames " + b.FirstFrame + " à " + b.LastFrame + " encodé à la position :" + LastAddedBlockPos.ToString() + "réduit de " + b.TotalSize + " à " + compress_size);
                }
                File.Delete(CurrentNodeFileName + ".2");
            }
            else
            {
                //le block est déja dans le fichier
                FileSource.Seek(StartPosition + TotalSize, SeekOrigin.Begin);    //on se met la ou on doit ajouter le block encodé
                long start_pos = FileSource.Position;

                FileSource.Write(Encoding.ASCII.GetBytes(CurrentNodeFileName), 0, CurrentNodeFileName.Length);    //ce n'est pas les nom des fichier qui sont encodé mais
                BlockMarker(FileSource);

                long compress_size = (FileSource.Position - start_pos);

                addBlockSize(start_pos, compress_size, b.FrameInBlock, b.FirstFrame);    //la taille à changé puisqu'on encode

                Console.WriteLine("arbre (d=" + Depth + ") contenant " + b.FirstFrame + " à " + b.LastFrame + "  laissé à la position :" + LastAddedBlockPos.ToString() + "de taille" + b.TotalSize);
            }
            blockCount++;//on a un block de plus
        }
Esempio n. 2
0
        internal virtual void addChildBlock(BlockType b, Stream bl_st, bool force_copy = false)
        {
            if (Top.EncodingNeeded(depth) || IsCompressed())//on doit encoder ?
            {
                SetCompressed();
                b.GoStartIndex(bl_st);
                using (FileStream childCopy = new FileStream("temp", FileMode.Create))
                {
                    bl_st.CopyTo(childCopy);
                    FileSource.Seek(StartPosition + TotalSize, SeekOrigin.Begin);//on se met la ou on doit ajouter le block encodé
                    childCopy.Seek(0, SeekOrigin.Begin);
                    childCopy.SetLength(b.TotalSize);

                    long start_pos = FileSource.Position;

                    Top.Encode(childCopy, FileSource, b.TotalSize, -1);//encodage de l'abre enfant
                    BlockMarker(FileSource);
                    long compress_size = (FileSource.Position - start_pos);

                    addBlockSize(start_pos, compress_size, b.FrameInBlock, b.FirstFrame);//la taille à changé puisqu'on encode
                    Console.WriteLine("arbre (d=" + Depth + ") contenant les frames " + b.FirstFrame + " à " + b.LastFrame + " encodé à la position :" + LastAddedBlockPos.ToString() + "réduit de " + b.TotalSize + " à " + compress_size);
                }
            }
            else
            {
                if (force_copy)
                {
                    b.GoStartIndex(bl_st);
                    using (FileStream childCopy = new FileStream("temp", FileMode.Create))
                    {
                        bl_st.CopyTo(childCopy);
                        childCopy.Seek(0, SeekOrigin.Begin);
                        Top.Output.Seek(StartPosition + TotalSize, SeekOrigin.Begin);//on se met la ou on doit ajouter le block encodé

                        childCopy.SetLength(b.TotalSize);
                        childCopy.CopyTo(FileSource);
                        BlockMarker(FileSource);                                                                //marker de début de block
                        addBlockSize(StartPosition + TotalSize, b.TotalSize + 1, b.FrameInBlock, b.FirstFrame); //taille est inchangé

                        Console.WriteLine("arbre (d=" + Depth + ") contenant les frames " + b.FirstFrame + " à " + b.LastFrame + "  copié à la position :" + LastAddedBlockPos.ToString() + "de taille" + childCopy.Length);
                    }
                }
                else
                {
                    //le block est déja dans le fichier
                    addBlockSize(b.StartPosition, b.TotalSize + 1, b.FrameInBlock, b.FirstFrame); //taille est inchangé$
                    Top.Output.Seek(StartPosition + TotalSize, SeekOrigin.Begin);                 //on se met à la fin
                    BlockMarker(FileSource);


                    Console.WriteLine("arbre (d=" + Depth + ") contenant " + b.FirstFrame + " à " + b.LastFrame + "  laissé à la position :" + LastAddedBlockPos.ToString() + "de taille" + b.TotalSize);
                }
            }
            blockCount++;//on a un block de plus
        }