Beispiel #1
0
        private void Load()
        {
            Span <byte> data;

            using (var ms = new MemoryStream())
            {
                _source.CopyToStream(ms);
                ms.Position = 0;
                data        = new Span <byte>(ms.ToArray());
            }

            var rowsCount = (int)data.Slice(0, 4).To <uint>();
            var dataStart = data.IndexOf(DataSeparator);
            var rowSize   = rowsCount > 0 ? (dataStart - 4) / rowsCount : 0;

            var dataSection = data.Slice(dataStart);

            var rows = new List <DatRow>();

            for (var r = 0; r < rowsCount; r++)
            {
                var rowBytes = data.Slice(4 + r * rowSize, rowSize);
                var datRow   = new DatRow(ref rowBytes, ref dataSection, _spec, _idx);
                rows.Add(datRow);
            }

            _rows     = rows;
            _isLoaded = true;
        }
Beispiel #2
0
        public static void Extract(this IFile file, string path)
        {
            var destFile = new FileInfo(path);

            if (!destFile.Directory !.Exists)
            {
                destFile.Directory.Create();
            }

            using var fs = destFile.Exists ? destFile.OpenWrite() : destFile.Create();
            file.CopyToStream(fs);
        }
Beispiel #3
0
 public void CopyFrom(IFile file)
 {
     if (file is DiskFile diskFile)
     {
         File.Copy(diskFile.Path, Path, true);
     }
     else
     {
         using (var fs = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Write,
                                        FileShare.None, WriteStreamBuffer, FileOptions.None))
         {
             file.CopyToStream(fs);
         }
     }
 }