From f1f44840839d856a421feba66e55cba0cc4266c3 Mon Sep 17 00:00:00 2001 From: Sergey Gorbunov Date: Fri, 18 Oct 2019 19:40:11 +0300 Subject: [PATCH] Method only for reading metadata. Fix for reading large memo-files. --- dBASE.NET/Dbf.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dBASE.NET/Dbf.cs b/dBASE.NET/Dbf.cs index f4c9491..84c90a9 100644 --- a/dBASE.NET/Dbf.cs +++ b/dBASE.NET/Dbf.cs @@ -82,6 +82,20 @@ public void Read(string path) } } + /// + /// Opens a DBF file, reads only database description and fields descriptors, and then closes the file. + /// + /// The file to read. + public void ReadMetadata(string path) + { + using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read)) + using (BinaryReader reader = new BinaryReader(stream)) + { + ReadHeader(reader); + ReadFields(reader); + } + } + /// /// Creates a new file, writes the current instance to the file, and then closes the file. If the target file already exists, it is overwritten. /// @@ -142,7 +156,7 @@ private static byte[] ReadMemos(string path) FileStream str = File.Open(memoPath, FileMode.Open, FileAccess.Read); BinaryReader memoReader = new BinaryReader(str); byte[] memoData = new byte[str.Length]; - memoData = memoReader.ReadBytes((int)str.Length); + memoReader.Read(memoData, 0, memoData.Length); memoReader.Close(); str.Close(); return memoData;