public CompoundFile(string path, CompoundFileOptions options, IFileStreamFactory fileStreamFactory) { Debug.Assert(UINT_ZERO.Length == sizeof(uint)); FileOptions foptions; if (options.UseWriteCache) foptions = FileOptions.RandomAccess; else foptions = FileOptions.RandomAccess | FileOptions.WriteThrough; _options = options; bool fileExists = File.Exists(path); lock (_sync) { _stream = fileStreamFactory.Create(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, options.BufferSize, foptions); if (!TryLoadFileHeader()) { if (fileExists) { if (_header.Version < FILE_VERSION) throw new InvalidDataException("File version is not supported"); if (!new System.Text.ASCIIEncoding().GetString(_header.Magic).Equals(MAGIC_STRING)) throw new InvalidDataException("Corrupt file"); throw new Exception("Failed to open file. Possible corrupt file"); } InitializeFile(); } } }
public CompoundFile(string path, CompoundFileOptions options) : this(path, options, new FileStreamFactory()) { }