diff --git a/common.props b/common.props index 0195c11f..7f2c1157 100644 --- a/common.props +++ b/common.props @@ -1,6 +1,6 @@ - 2.7.5.1 + 2.7.5.2 true snupkg 1591 @@ -30,9 +30,9 @@ 1701;1702;CS1591;CS1573 - + all - runtime; build; native; contentfiles; analyzers + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/EPPlus/EPPlus/Compatibility/ImageCompat.cs b/src/EPPlus/EPPlus/Compatibility/ImageCompat.cs index 4db24dc6..c64c1e91 100644 --- a/src/EPPlus/EPPlus/Compatibility/ImageCompat.cs +++ b/src/EPPlus/EPPlus/Compatibility/ImageCompat.cs @@ -1,4 +1,5 @@ -using OfficeOpenXml.Utils; +using System.IO; +using OfficeOpenXml.Utils; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats; @@ -8,7 +9,7 @@ internal class ImageCompat { internal static byte[] GetImageAsByteArray(Image image, IImageFormat format) { - using (var ms = RecyclableMemoryStream.GetStream()) + using (var ms = new MemoryStream()) { image.Save(ms, format); return ms.ToArray(); diff --git a/src/EPPlus/EPPlus/Encryption/EncryptionHandler.cs b/src/EPPlus/EPPlus/Encryption/EncryptionHandler.cs index 58ec9fef..bbfb6e55 100644 --- a/src/EPPlus/EPPlus/Encryption/EncryptionHandler.cs +++ b/src/EPPlus/EPPlus/Encryption/EncryptionHandler.cs @@ -173,15 +173,15 @@ private MemoryStream EncryptPackageAgile(byte[] package, ExcelEncryption encrypt var VerifierHashKey = GetFinalHash(hashProvider, BlockKey_HashValue, baseHash); var KeyValueKey = GetFinalHash(hashProvider, BlockKey_KeyValue, baseHash); - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); EncryptAgileFromKey(encr, VerifierInputKey, encr.VerifierHashInput, 0, encr.VerifierHashInput.Length, encr.SaltValue, ms); encr.EncryptedVerifierHashInput = ms.ToArray(); - ms = RecyclableMemoryStream.GetStream(); + ms = new MemoryStream(); EncryptAgileFromKey(encr, VerifierHashKey, encr.VerifierHash, 0, encr.VerifierHash.Length, encr.SaltValue, ms); encr.EncryptedVerifierHash = ms.ToArray(); - ms = RecyclableMemoryStream.GetStream(); + ms = new MemoryStream(); EncryptAgileFromKey(encr, KeyValueKey, encr.KeyValue, 0, encr.KeyValue.Length, encr.SaltValue, ms); encr.EncryptedKeyValue = ms.ToArray(); @@ -189,7 +189,7 @@ private MemoryStream EncryptPackageAgile(byte[] package, ExcelEncryption encrypt var byXml = Encoding.UTF8.GetBytes(xml); - ms = RecyclableMemoryStream.GetStream(); + ms = new MemoryStream(); ms.Write(BitConverter.GetBytes((ushort)4), 0, 2); //Major Version ms.Write(BitConverter.GetBytes((ushort)4), 0, 2); //Minor Version ms.Write(BitConverter.GetBytes((uint)0x40), 0, 4); //Reserved @@ -204,7 +204,7 @@ private MemoryStream EncryptPackageAgile(byte[] package, ExcelEncryption encrypt //...and the encrypted package doc.Storage.DataStreams.Add("EncryptedPackage", encrData); - ms = RecyclableMemoryStream.GetStream(); + ms = new MemoryStream(); doc.Save(ms); //ms.Write(e,0,e.Length); return ms; @@ -226,7 +226,7 @@ private byte[] EncryptDataAgile(byte[] data, EncryptionInfoAgile encryptionInfo, int segment = 0; //Encrypt the data - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); ms.Write(BitConverter.GetBytes((ulong)data.Length), 0, 8); while (pos < data.Length) { @@ -248,14 +248,14 @@ private byte[] EncryptDataAgile(byte[] data, EncryptionInfoAgile encryptionInfo, private void SetHMAC(EncryptionInfoAgile ei, HashAlgorithm hashProvider, byte[] salt, byte[] data) { var iv = GetFinalHash(hashProvider, BlockKey_HmacKey, ei.KeyData.SaltValue); - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); EncryptAgileFromKey(ei.KeyEncryptors[0], ei.KeyEncryptors[0].KeyValue, salt, 0L, salt.Length, iv, ms); ei.DataIntegrity.EncryptedHmacKey = ms.ToArray(); var h = GetHmacProvider(ei.KeyEncryptors[0], salt); var hmacValue = h.ComputeHash(data); - ms = RecyclableMemoryStream.GetStream(); + ms = new MemoryStream(); iv = GetFinalHash(hashProvider, BlockKey_HmacValue, ei.KeyData.SaltValue); EncryptAgileFromKey(ei.KeyEncryptors[0], ei.KeyEncryptors[0].KeyValue, hmacValue, 0L, hmacValue.Length, iv, ms); ei.DataIntegrity.EncryptedHmacValue = ms.ToArray(); @@ -308,12 +308,12 @@ private MemoryStream EncryptPackageBinary(byte[] package, ExcelEncryption encryp //Encrypt the package byte[] encryptedPackage = EncryptData(encryptionKey, package, false); - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); ms.Write(BitConverter.GetBytes((ulong)package.Length), 0, 8); ms.Write(encryptedPackage, 0, encryptedPackage.Length); doc.Storage.DataStreams.Add("EncryptedPackage", ms.ToArray()); - var ret = RecyclableMemoryStream.GetStream(); + var ret = new MemoryStream(); doc.Save(ret); return ret; @@ -341,7 +341,7 @@ private void CreateDataSpaces(CompoundDocument doc) } private byte[] CreateStrongEncryptionDataSpaceStream() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write((int)8); //HeaderLength @@ -356,7 +356,7 @@ private byte[] CreateStrongEncryptionDataSpaceStream() } private byte[] CreateVersionStream() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write((short)0x3C); //Major @@ -371,7 +371,7 @@ private byte[] CreateVersionStream() } private byte[] CreateDataSpaceMap() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write((int)8); //HeaderLength @@ -391,7 +391,7 @@ private byte[] CreateDataSpaceMap() } private byte[] CreateTransformInfoPrimary() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); string TransformID = "{FF9A3F03-56EF-4613-BDD5-5A41C1D07246}"; string TransformName = "Microsoft.Container.EncryptionTransform"; @@ -485,7 +485,7 @@ private byte[] EncryptData(byte[] key, byte[] data, bool useDataSize) //Encrypt the data var crypt = aes.CreateEncryptor(key, null); - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); var cs = new CryptoStream(ms, crypt, CryptoStreamMode.Write); cs.Write(data, 0, data.Length); @@ -506,7 +506,7 @@ private byte[] EncryptData(byte[] key, byte[] data, bool useDataSize) } private MemoryStream GetStreamFromPackage(CompoundDocument doc, ExcelEncryption encryption) { - //var ret = RecyclableMemoryStream.GetStream(); + //var ret = new MemoryStream(); if (doc.Storage.DataStreams.ContainsKey("EncryptionInfo") || doc.Storage.DataStreams.ContainsKey("EncryptedPackage")) { @@ -553,7 +553,7 @@ private MemoryStream DecryptDocument(byte[] data, EncryptionInfo encryptionInfo, private MemoryStream DecryptAgile(EncryptionInfoAgile encryptionInfo, string password, long size, byte[] encryptedData, byte[] data) { - MemoryStream doc = RecyclableMemoryStream.GetStream(); + MemoryStream doc = new MemoryStream(); if (encryptionInfo.KeyData.CipherAlgorithm == eCipherAlgorithm.AES) { @@ -665,7 +665,7 @@ private HashAlgorithm GetHashProvider(EncryptionInfoAgile.EncryptionKeyData encr #endif private MemoryStream DecryptBinary(EncryptionInfoBinary encryptionInfo, string password, long size, byte[] encryptedData) { - MemoryStream doc = RecyclableMemoryStream.GetStream(); + MemoryStream doc = new MemoryStream(); if (encryptionInfo.Header.AlgID == AlgorithmID.AES128 || (encryptionInfo.Header.AlgID == AlgorithmID.Flags && ((encryptionInfo.Flags & (Flags.fAES | Flags.fExternal | Flags.fCryptoAPI)) == (Flags.fAES | Flags.fCryptoAPI))) || @@ -690,7 +690,7 @@ private MemoryStream DecryptBinary(EncryptionInfoBinary encryptionInfo, string p key, null); - var dataStream = RecyclableMemoryStream.GetStream(encryptedData); + var dataStream = new MemoryStream(encryptedData); var cryptoStream = new CryptoStream(dataStream, decryptor, CryptoStreamMode.Read); @@ -730,14 +730,14 @@ private bool IsPasswordValid(byte[] key, EncryptionInfoBinary encryptionInfo) //Decrypt the verifier - MemoryStream dataStream = RecyclableMemoryStream.GetStream(encryptionInfo.Verifier.EncryptedVerifier); + MemoryStream dataStream = new MemoryStream(encryptionInfo.Verifier.EncryptedVerifier); CryptoStream cryptoStream = new CryptoStream(dataStream, decryptor, CryptoStreamMode.Read); var decryptedVerifier = new byte[16]; cryptoStream.Read(decryptedVerifier, 0, 16); - dataStream = RecyclableMemoryStream.GetStream(encryptionInfo.Verifier.EncryptedVerifierHash); + dataStream = new MemoryStream(encryptionInfo.Verifier.EncryptedVerifierHash); cryptoStream = new CryptoStream(dataStream, decryptor, @@ -803,7 +803,7 @@ private byte[] DecryptAgileFromKey(EncryptionInfoAgile.EncryptionKeyData encr, b FixHashSize(iv, encr.BlockSize, 0x36)); - MemoryStream dataStream = RecyclableMemoryStream.GetStream(encryptedData); + MemoryStream dataStream = new MemoryStream(encryptedData); CryptoStream cryptoStream = new CryptoStream(dataStream, decryptor, diff --git a/src/EPPlus/EPPlus/Encryption/EncryptionHeader.cs b/src/EPPlus/EPPlus/Encryption/EncryptionHeader.cs index 18ccd53c..5603c0bf 100644 --- a/src/EPPlus/EPPlus/Encryption/EncryptionHeader.cs +++ b/src/EPPlus/EPPlus/Encryption/EncryptionHeader.cs @@ -80,7 +80,7 @@ internal class EncryptionHeader internal string CSPName; //SHOULD<11> be set to either "Microsoft Enhanced RSA and AES Cryptographic Provider" or "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)" as a null-terminated Unicode string. internal byte[] WriteBinary() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write((int)Flags); diff --git a/src/EPPlus/EPPlus/Encryption/EncryptionInfo.cs b/src/EPPlus/EPPlus/Encryption/EncryptionInfo.cs index 8a5708f6..974a5629 100644 --- a/src/EPPlus/EPPlus/Encryption/EncryptionInfo.cs +++ b/src/EPPlus/EPPlus/Encryption/EncryptionInfo.cs @@ -566,7 +566,7 @@ internal override void Read(byte[] data) } internal byte[] WriteBinary() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write(MajorVersion); diff --git a/src/EPPlus/EPPlus/Encryption/EncryptionVerifier.cs b/src/EPPlus/EPPlus/Encryption/EncryptionVerifier.cs index 946d20e7..76a2b507 100644 --- a/src/EPPlus/EPPlus/Encryption/EncryptionVerifier.cs +++ b/src/EPPlus/EPPlus/Encryption/EncryptionVerifier.cs @@ -45,7 +45,7 @@ internal class EncryptionVerifier internal byte[] EncryptedVerifierHash; //(variable): An array of bytes that contains the encrypted form of the hash of the randomly generated Verifier value. The length of the array MUST be the size of the encryption block size multiplied by the number of blocks needed to encrypt the hash of the Verifier. If the encryption algorithm is RC4, the length MUST be 20 bytes. If the encryption algorithm is AES, the length MUST be 32 bytes. internal byte[] WriteBinary() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write(SaltSize); diff --git a/src/EPPlus/EPPlus/ExcelPackage.cs b/src/EPPlus/EPPlus/ExcelPackage.cs index 8c8c2080..b9cfefd6 100644 --- a/src/EPPlus/EPPlus/ExcelPackage.cs +++ b/src/EPPlus/EPPlus/ExcelPackage.cs @@ -555,8 +555,8 @@ private void CreateFromTemplate(FileInfo template, string password) if (template != null) template.Refresh(); if (template.Exists) { - if (_stream == null) _stream = RecyclableMemoryStream.GetStream(); - var ms = RecyclableMemoryStream.GetStream(); + if (_stream == null) _stream = new MemoryStream(); + var ms = new MemoryStream(); if (password != null) { Encryption.IsEncrypted = true; @@ -592,8 +592,8 @@ private void CreateFromTemplate(FileInfo template, string password) } private void ConstructNewFile(string password) { - var ms = RecyclableMemoryStream.GetStream(); - if (_stream == null) _stream = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); + if (_stream == null) _stream = new MemoryStream(); if (File != null) File.Refresh(); if (File != null && File.Exists) { @@ -842,7 +842,7 @@ public void Save() { if (Encryption.IsEncrypted) { - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); _package.Save(ms); byte[] file = ms.ToArray(); EncryptedPackageHandler eph = new EncryptedPackageHandler(); @@ -999,7 +999,7 @@ internal void CloseStream() _stream.Dispose(); } - _stream = RecyclableMemoryStream.GetStream(); + _stream = new MemoryStream(); } /// /// The output stream. This stream is the not the encrypted package. @@ -1166,7 +1166,7 @@ internal async Task GetAsByteArrayAsync(bool save) /// The input. public void Load(Stream input) { - Load(input, RecyclableMemoryStream.GetStream(), null); + Load(input, new MemoryStream(), null); } /// /// Loads the specified package data from a stream. @@ -1175,7 +1175,7 @@ public void Load(Stream input) /// The password to decrypt the document public void Load(Stream input, string Password) { - Load(input, RecyclableMemoryStream.GetStream(), Password); + Load(input, new MemoryStream(), Password); } /// /// @@ -1205,7 +1205,7 @@ private void Load(Stream input, Stream output, string Password) } else { - Stream ms = RecyclableMemoryStream.GetStream(); + Stream ms = new MemoryStream(); this._stream = output; if (Password != null) { diff --git a/src/EPPlus/EPPlus/ExcelWorksheet.cs b/src/EPPlus/EPPlus/ExcelWorksheet.cs index 262265ea..38eb5c25 100644 --- a/src/EPPlus/EPPlus/ExcelWorksheet.cs +++ b/src/EPPlus/EPPlus/ExcelWorksheet.cs @@ -899,7 +899,7 @@ private void CreateXml() // now release stream buffer (already converted whole Xml into XmlDocument Object and String) stream.Dispose(); - packPart.Stream = RecyclableMemoryStream.GetStream(); + packPart.Stream = new MemoryStream(); //first char is invalid sometimes?? if (xml[0] != '<') diff --git a/src/EPPlus/EPPlus/Magicodes.IE.EPPlus.csproj b/src/EPPlus/EPPlus/Magicodes.IE.EPPlus.csproj index 00f4f79a..b8d9e231 100644 --- a/src/EPPlus/EPPlus/Magicodes.IE.EPPlus.csproj +++ b/src/EPPlus/EPPlus/Magicodes.IE.EPPlus.csproj @@ -53,7 +53,6 @@ - diff --git a/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.AddUpdate.cs b/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.AddUpdate.cs index 57847654..ee6e2812 100644 --- a/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.AddUpdate.cs +++ b/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.AddUpdate.cs @@ -1199,7 +1199,7 @@ public ZipEntry AddEntry(string entryName, string content, System.Text.Encoding { // cannot employ a using clause here. We need the stream to // persist after exit from this method. - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); // cannot use a using clause here; StreamWriter takes // ownership of the stream and Disposes it before we are ready. @@ -1858,7 +1858,7 @@ private void RemoveEntryForUpdate(string entryName) public ZipEntry AddEntry(string entryName, byte[] byteContent) { if (byteContent == null) throw new ArgumentException("bad argument", "byteContent"); - var ms = RecyclableMemoryStream.GetStream(byteContent); + var ms = new MemoryStream(byteContent); return AddEntry(entryName, ms); } diff --git a/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.Save.cs b/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.Save.cs index 164cb628..5aa3f0e7 100644 --- a/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.Save.cs +++ b/src/EPPlus/EPPlus/Packaging/DotNetZip/ZipFile.Save.cs @@ -522,7 +522,7 @@ public void Save(String fileName) /// zip.Password = "VerySecret."; /// zip.Encryption = EncryptionAlgorithm.WinZipAes128; /// zip.AddFile(sourceFileName); - /// MemoryStream output = RecyclableMemoryStream.GetStream(); + /// MemoryStream output = new MemoryStream(); /// zip.Save(output); /// /// byte[] zipbytes = output.ToArray(); @@ -606,7 +606,7 @@ public static bool WriteCentralDirectoryStructure(Stream s, // write to a memory stream in order to keep the // CDR contiguous Int64 aLength = 0; - using (var ms = RecyclableMemoryStream.GetStream()) + using (var ms = new MemoryStream()) { foreach (ZipEntry e in entries) { diff --git a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/GZipStream.cs b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/GZipStream.cs index b9a75203..238daede 100644 --- a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/GZipStream.cs +++ b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/GZipStream.cs @@ -946,7 +946,7 @@ private int EmitHeader() /// The string in compressed form public static byte[] CompressString(String s) { - using (var ms = RecyclableMemoryStream.GetStream()) + using (var ms = new MemoryStream()) { System.IO.Stream compressor = new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression); @@ -974,7 +974,7 @@ public static byte[] CompressString(String s) /// The data in compressed form public static byte[] CompressBuffer(byte[] b) { - using (var ms = RecyclableMemoryStream.GetStream()) + using (var ms = new MemoryStream()) { System.IO.Stream compressor = new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression); @@ -999,7 +999,7 @@ public static byte[] CompressBuffer(byte[] b) /// The uncompressed string public static String UncompressString(byte[] compressed) { - using (var input = RecyclableMemoryStream.GetStream(compressed)) + using (var input = new MemoryStream(compressed)) { Stream decompressor = new GZipStream(input, CompressionMode.Decompress); return ZlibBaseStream.UncompressString(compressed, decompressor); diff --git a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibBaseStream.cs b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibBaseStream.cs index bfc38377..c075d89b 100644 --- a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibBaseStream.cs +++ b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibBaseStream.cs @@ -589,7 +589,7 @@ public static String UncompressString(byte[] compressed, Stream decompressor) // workitem 8460 byte[] working = new byte[1024]; var encoding = System.Text.Encoding.UTF8; - using (var output = RecyclableMemoryStream.GetStream()) + using (var output = new MemoryStream()) { using (decompressor) { @@ -611,7 +611,7 @@ public static byte[] UncompressBuffer(byte[] compressed, Stream decompressor) { // workitem 8460 byte[] working = new byte[1024]; - using (var output = RecyclableMemoryStream.GetStream()) + using (var output = new MemoryStream()) { using (decompressor) { diff --git a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibCodec.cs b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibCodec.cs index a7a5a6b3..ce5285d1 100644 --- a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibCodec.cs +++ b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibCodec.cs @@ -528,7 +528,7 @@ private int _InternalInitializeDeflate(bool wantRfc1950Header) /// /// Console.WriteLine("\n============================================"); /// Console.WriteLine("Size of Buffer to Deflate: {0} bytes.", UncompressedBytes.Length); - /// MemoryStream ms = RecyclableMemoryStream.GetStream(); + /// MemoryStream ms = new MemoryStream(); /// /// int rc = compressor.InitializeDeflate(level); /// diff --git a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibStream.cs b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibStream.cs index 9d111232..175669e5 100644 --- a/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibStream.cs +++ b/src/EPPlus/EPPlus/Packaging/DotNetZip/Zlib/ZlibStream.cs @@ -634,7 +634,7 @@ public override void Write(byte[] buffer, int offset, int count) /// The string in compressed form public static byte[] CompressString(String s) { - using (var ms = RecyclableMemoryStream.GetStream()) + using (var ms = new MemoryStream()) { Stream compressor = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression); @@ -662,7 +662,7 @@ public static byte[] CompressString(String s) /// The data in compressed form public static byte[] CompressBuffer(byte[] b) { - using (var ms = RecyclableMemoryStream.GetStream()) + using (var ms = new MemoryStream()) { Stream compressor = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression); @@ -687,7 +687,7 @@ public static byte[] CompressBuffer(byte[] b) /// The uncompressed string public static String UncompressString(byte[] compressed) { - using (var input = RecyclableMemoryStream.GetStream(compressed)) + using (var input = new MemoryStream(compressed)) { Stream decompressor = new ZlibStream(input, CompressionMode.Decompress); @@ -711,7 +711,7 @@ public static String UncompressString(byte[] compressed) /// The data in uncompressed form public static byte[] UncompressBuffer(byte[] compressed) { - using (var input = RecyclableMemoryStream.GetStream(compressed)) + using (var input = new MemoryStream(compressed)) { Stream decompressor = new ZlibStream(input, CompressionMode.Decompress); diff --git a/src/EPPlus/EPPlus/Packaging/ZipPackage.cs b/src/EPPlus/EPPlus/Packaging/ZipPackage.cs index 5f6a54f8..fc2d8c6a 100644 --- a/src/EPPlus/EPPlus/Packaging/ZipPackage.cs +++ b/src/EPPlus/EPPlus/Packaging/ZipPackage.cs @@ -140,7 +140,7 @@ private void ProcessEntry(ZipEntry e, Dictionary rels, Stream zi else { var part = new ZipPackagePart(this, e); - part.Stream = RecyclableMemoryStream.GetStream(); + part.Stream = new MemoryStream(); zip.CopyTo(part.Stream); Parts.Add(GetUriKey(e.FileName), part); } diff --git a/src/EPPlus/EPPlus/Packaging/ZipPackagePart.cs b/src/EPPlus/EPPlus/Packaging/ZipPackagePart.cs index baaff4f9..dbf8e331 100644 --- a/src/EPPlus/EPPlus/Packaging/ZipPackagePart.cs +++ b/src/EPPlus/EPPlus/Packaging/ZipPackagePart.cs @@ -90,7 +90,7 @@ internal MemoryStream GetStream(FileMode fileMode, FileAccess fileAccess) { if (_stream == null || fileMode == FileMode.CreateNew || fileMode == FileMode.Create) { - _stream = RecyclableMemoryStream.GetStream(); + _stream = new MemoryStream(); } else { @@ -122,7 +122,7 @@ internal set public Uri Uri { get; private set; } public Stream GetZipStream() { - MemoryStream ms = RecyclableMemoryStream.GetStream(); + MemoryStream ms = new MemoryStream(); ZipOutputStream os = new ZipOutputStream(ms); return os; } diff --git a/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocument.cs b/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocument.cs index 2ad3b08a..33d94dbd 100644 --- a/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocument.cs +++ b/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocument.cs @@ -80,7 +80,7 @@ internal void Read(FileInfo fi) } internal void Read(byte[] doc) { - Read(RecyclableMemoryStream.GetStream(doc)); + Read(new MemoryStream(doc)); } internal void Read(MemoryStream ms) { diff --git a/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocumentFile.cs b/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocumentFile.cs index 531826f5..3d69043e 100644 --- a/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocumentFile.cs +++ b/src/EPPlus/EPPlus/Utils/CompundDocument/CompoundDocumentFile.cs @@ -56,7 +56,7 @@ internal CompoundDocumentFile(FileInfo fi) : this(File.ReadAllBytes(fi.FullName) { } - public CompoundDocumentFile(byte[] file) : this(RecyclableMemoryStream.GetStream(file)) + public CompoundDocumentFile(byte[] file) : this(new MemoryStream(file)) { } public CompoundDocumentFile(MemoryStream ms) @@ -209,7 +209,7 @@ private void LoadDIFATSectors(DocWriteInfo dwi) var nextSector = _firstDIFATSectorLocation; while (nextSector > 0) { - var brDI = new BinaryReader(RecyclableMemoryStream.GetStream(_sectors[nextSector])); + var brDI = new BinaryReader(new MemoryStream(_sectors[nextSector])); var sect = -1; while (brDI.BaseStream.Position < _sectorSize) { @@ -238,7 +238,7 @@ private void LoadMinSectors(ref DocWriteInfo dwi, List dir } private void GetMiniSectors(byte[] miniFATStream) { - var br = new BinaryReader(RecyclableMemoryStream.GetStream(miniFATStream)); + var br = new BinaryReader(new MemoryStream(miniFATStream)); _miniSectors = new List(); while (br.BaseStream.Position < br.BaseStream.Length) { @@ -247,7 +247,7 @@ private void GetMiniSectors(byte[] miniFATStream) } private byte[] GetStream(int startingSectorLocation, long streamSize, List FAT, List sectors) { - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); var bw = new BinaryWriter(ms); var size = 0; @@ -277,7 +277,7 @@ private List ReadMiniFAT(List sectors, DocWriteInfo dwi) var nextSector = _firstMiniFATSectorLocation; while (nextSector != END_OF_CHAIN) { - var br = new BinaryReader(RecyclableMemoryStream.GetStream(sectors[nextSector])); + var br = new BinaryReader(new MemoryStream(sectors[nextSector])); while (br.BaseStream.Position < _sectorSize) { var d = br.ReadInt32(); @@ -303,7 +303,7 @@ private List ReadFAT(List sectors, DocWriteInfo dwi) var l = new List(); foreach (var i in dwi.DIFAT) { - var br = new BinaryReader(RecyclableMemoryStream.GetStream(sectors[i])); + var br = new BinaryReader(new MemoryStream(sectors[i])); while (br.BaseStream.Position < _sectorSize) { var d = br.ReadInt32(); @@ -315,7 +315,7 @@ private List ReadFAT(List sectors, DocWriteInfo dwi) private void ReadDirectory(List sectors, int index, List l) { - var br = new BinaryReader(RecyclableMemoryStream.GetStream(sectors[index])); + var br = new BinaryReader(new MemoryStream(sectors[index])); while (br.BaseStream.Position < br.BaseStream.Length) { @@ -840,9 +840,9 @@ private int GetSectors(int v, int size) private byte[] SetMiniStream(List dirs) { //Create the miniStream - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); var bwMiniFATStream = new BinaryWriter(ms); - var bwMiniFAT = new BinaryWriter(RecyclableMemoryStream.GetStream()); + var bwMiniFAT = new BinaryWriter(new MemoryStream()); int pos = 0; foreach (var entity in dirs) { diff --git a/src/EPPlus/EPPlus/Utils/RecyclableMemoryStream.cs b/src/EPPlus/EPPlus/Utils/RecyclableMemoryStream.cs deleted file mode 100644 index 5648b291..00000000 --- a/src/EPPlus/EPPlus/Utils/RecyclableMemoryStream.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.IO; -using System; -using System.IO; - -namespace OfficeOpenXml.Utils -{ - public static class RecyclableMemoryStream - { - private static readonly Lazy recyclableMemoryStreamManager = new Lazy(); - private static RecyclableMemoryStreamManager RecyclableMemoryStreamManager - { - get - { - var recyclableMemoryStream = recyclableMemoryStreamManager.Value; - recyclableMemoryStream.MaximumFreeSmallPoolBytes = 64 * 1024 * 1024; - recyclableMemoryStream.MaximumFreeLargePoolBytes = 64 * 1024 * 32; - recyclableMemoryStream.AggressiveBufferReturn = true; - return recyclableMemoryStream; - } - } - private const string TagSource = "Magicodes.EPPlus"; - - internal static MemoryStream GetStream() - { - return RecyclableMemoryStreamManager.GetStream(TagSource); - } - - internal static MemoryStream GetStream(byte[] array) - { - return RecyclableMemoryStreamManager.GetStream(array); - } - - internal static MemoryStream GetStream(int capacity) - { - return RecyclableMemoryStreamManager.GetStream(TagSource, capacity); - } - } -} diff --git a/src/EPPlus/EPPlus/Utils/VBACompression.cs b/src/EPPlus/EPPlus/Utils/VBACompression.cs index 86cb2cc8..f8c37a52 100644 --- a/src/EPPlus/EPPlus/Utils/VBACompression.cs +++ b/src/EPPlus/EPPlus/Utils/VBACompression.cs @@ -45,7 +45,7 @@ internal static class VBACompression /// internal static byte[] CompressPart(byte[] part) { - using (var ms = RecyclableMemoryStream.GetStream(4096)) + using (var ms = new MemoryStream(4096)) { BinaryWriter br = new BinaryWriter(ms); br.Write((byte)1); @@ -172,7 +172,7 @@ internal static byte[] DecompressPart(byte[] part, int startPos) return null; } - using (var ms = RecyclableMemoryStream.GetStream(4096)) + using (var ms = new MemoryStream(4096)) { int compressPos = startPos + 1; while (compressPos < part.Length - 1) diff --git a/src/EPPlus/EPPlus/VBA/ExcelVBAProject.cs b/src/EPPlus/EPPlus/VBA/ExcelVBAProject.cs index 2d55b51b..bdf2bdf4 100644 --- a/src/EPPlus/EPPlus/VBA/ExcelVBAProject.cs +++ b/src/EPPlus/EPPlus/VBA/ExcelVBAProject.cs @@ -342,7 +342,7 @@ private string Encrypt(byte[] value) byte[] seed = new byte[1]; var rn = RandomNumberGenerator.Create(); rn.GetBytes(seed); - BinaryWriter br = new BinaryWriter(RecyclableMemoryStream.GetStream()); + BinaryWriter br = new BinaryWriter(new MemoryStream()); byte[] enc = new byte[value.Length + 10]; enc[0] = seed[0]; enc[1] = (byte)(2 ^ seed[0]); @@ -401,7 +401,7 @@ private byte[] GetByte(string value) private void ReadDirStream() { byte[] dir = VBACompression.DecompressPart(Document.Storage.SubStorage["VBA"].DataStreams["dir"]); - using (MemoryStream ms = RecyclableMemoryStream.GetStream(dir)) + using (MemoryStream ms = new MemoryStream(dir)) { BinaryReader br = new BinaryReader(ms); @@ -623,7 +623,7 @@ private bool Validate() /// private byte[] CreateVBAProjectStream() { - BinaryWriter bw = new BinaryWriter(RecyclableMemoryStream.GetStream()); + BinaryWriter bw = new BinaryWriter(new MemoryStream()); bw.Write((ushort)0x61CC); //Reserved1 bw.Write((ushort)0xFFFF); //Version bw.Write((byte)0x0); //Reserved3 @@ -636,7 +636,7 @@ private byte[] CreateVBAProjectStream() /// private byte[] CreateDirStream() { - BinaryWriter bw = new BinaryWriter(RecyclableMemoryStream.GetStream()); + BinaryWriter bw = new BinaryWriter(new MemoryStream()); /****** PROJECTINFORMATION Record ******/ bw.Write((ushort)1); //ID @@ -861,7 +861,7 @@ private void WriteRegisteredReference(BinaryWriter bw, ExcelVbaReference referen private byte[] CreateProjectwmStream() { - BinaryWriter bw = new BinaryWriter(RecyclableMemoryStream.GetStream()); + BinaryWriter bw = new BinaryWriter(new MemoryStream()); foreach (var module in Modules) { @@ -977,7 +977,7 @@ private string WritePassword() } } //Write the Password Hash Data Structure (2.4.4.1) - BinaryWriter bw = new BinaryWriter(RecyclableMemoryStream.GetStream()); + BinaryWriter bw = new BinaryWriter(new MemoryStream()); bw.Write((byte)0xFF); bw.Write(nullBits); bw.Write(nullKey); diff --git a/src/EPPlus/EPPlus/VBA/ExcelVBASignature.cs b/src/EPPlus/EPPlus/VBA/ExcelVBASignature.cs index 7302b71c..8221f41f 100644 --- a/src/EPPlus/EPPlus/VBA/ExcelVBASignature.cs +++ b/src/EPPlus/EPPlus/VBA/ExcelVBASignature.cs @@ -172,7 +172,7 @@ internal void Save(ExcelVbaProject proj) return; } } - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); var bw = new BinaryWriter(ms); byte[] certStore = GetCertStore(); @@ -248,7 +248,7 @@ private X509Certificate2 GetCertFromStore(StoreLocation loc) private byte[] GetCertStore() { - var ms = RecyclableMemoryStream.GetStream(); + var ms = new MemoryStream(); var bw = new BinaryWriter(ms); bw.Write((uint)0); //Version @@ -286,7 +286,7 @@ internal byte[] SignProject(ExcelVbaProject proj) } var hash = GetContentHash(proj); - BinaryWriter bw = new BinaryWriter(RecyclableMemoryStream.GetStream()); + BinaryWriter bw = new BinaryWriter(new MemoryStream()); bw.Write((byte)0x30); //Constructed Type bw.Write((byte)0x32); //Total length bw.Write((byte)0x30); //Constructed Type @@ -329,7 +329,7 @@ private byte[] GetContentHash(ExcelVbaProject proj) { //MS-OVBA 2.4.2 var enc = System.Text.Encoding.GetEncoding(proj.CodePage); - BinaryWriter bw = new BinaryWriter(RecyclableMemoryStream.GetStream()); + BinaryWriter bw = new BinaryWriter(new MemoryStream()); bw.Write(enc.GetBytes(proj.Name)); bw.Write(enc.GetBytes(proj.Constants)); foreach (var reference in proj.References) @@ -341,7 +341,7 @@ private byte[] GetContentHash(ExcelVbaProject proj) if (reference.ReferenceRecordID == 0x0E) { //var r = (ExcelVbaReferenceProject)reference; - //BinaryWriter bwTemp = new BinaryWriter(RecyclableMemoryStream.GetStream()); + //BinaryWriter bwTemp = new BinaryWriter(new MemoryStream()); //bwTemp.Write((uint)r.Libid.Length); //bwTemp.Write(enc.GetBytes(r.Libid)); //bwTemp.Write((uint)r.LibIdRelative.Length);