Esempio n. 1
0
        PieceDescriptorCollection GetPieceDescriptors(BinaryReader reader, int offset, uint length)
        {
            PieceDescriptorCollection result = new PieceDescriptorCollection(offset, length);

            result.Read(reader);
            return(result);
        }
Esempio n. 2
0
        bool LoadText(OleStorage storage, out string text)
        {
            text = string.Empty;
            if (storage == null)
            {
                return(false);
            }

            BinaryReader documentReader = GetDocumentStreamReader(storage);

            if (documentReader == null)
            {
                return(false);
            }

            int    pdcOffset;
            uint   pdcLength;
            string tableName;

            GetDataFromFib(documentReader, out tableName, out pdcOffset, out pdcLength);

            BinaryReader tableReader = GetTableStreamReader(storage, tableName);

            if (tableReader == null)
            {
                return(false);
            }

            PieceDescriptorCollection pieces = GetPieceDescriptors(tableReader, pdcOffset, pdcLength);

            if (pieces == null)
            {
                return(false);
            }

            //EDIT: Chris Wilson 04/01/16
            //We have had some performance issues with legacy word docs, and I suspect that
            //it's the use of overloaded operator concatenation in the below loop
            //rather than using a stringbuilder
            //change is to address this speed issue as we are encountering documents with word counts
            //in the several 100ks

            //ADDED: as per comment above
            StringBuilder builder = new StringBuilder();

            int count = pieces.Count;

            for (int i = 0; i < count; i++)
            {
                uint pieceStart;
                uint pieceEnd;
                bool isUnicode = pieces.GetPieceFileBounds(i, out pieceStart, out pieceEnd);

                documentReader.BaseStream.Seek(pieceStart, SeekOrigin.Begin);

                //REMOVED: Chris Wilson as per comment above
                //text += ReadString(documentReader, pieceEnd - pieceStart, isUnicode);

                //ADDED: Chris Wilson as per comment above
                builder.Append(ReadString(documentReader, pieceEnd - pieceStart, isUnicode));
            }

            //ADDED: Chris Wilson as per comment above
            text = builder.ToString();

            return(true);
        }