ironfede / openmcdf

Microsoft Compound File .net component - pure C# - netstandard 2.0
Mozilla Public License 2.0
302 stars 73 forks source link

Large files with UpdateMode #14

Closed ArminFirecracker closed 6 years ago

ArminFirecracker commented 6 years ago

When opening a file in update mode and appending big arrays, I get an exception:

System.ArgumentOutOfRangeException: 'Non-negative number required.

This could be fixed by casting in the corresponding line to long.

CompoundFile.cs, line 650 sourceStream.SetLength((long)(sectors.Count + 1) * sSize);

What do you say?

            String filename = "MyFile.dat";
            String storageName = "MyStorage";
            String streamName = "MyStream";
            int bufferSize = 500000000;
            int iterationCount = 3;
            int streamCount = 3;

            CompoundFile compoundFileInit = new CompoundFile(CFSVersion.Ver_4, CFSConfiguration.Default);
            compoundFileInit.Save(filename);
            compoundFileInit.Close();

            CompoundFile compoundFile = new CompoundFile(filename, CFSUpdateMode.Update, CFSConfiguration.Default);
            CFStorage st = compoundFile.RootStorage.AddStorage(storageName);

            for (int streamId = 0; streamId < streamCount; ++streamId)
            {
                CFStream sm = st.AddStream(streamName + streamId);
                for (int iteration = 0; iteration < iterationCount; ++iteration)
                {
                    sm.Append(new byte[bufferSize]);
                    compoundFile.Commit();
                }
            }
            compoundFile.Close();
ironfede commented 6 years ago

Thank you very much for your advice. Committed to main with unit test based on your code. Best Regards, Federico

ironfede commented 6 years ago

Nuget package released, 2.1.4.23498