/// <summary> /// Opens or creates a stream, initializing with bytes 0xFF if <paramref name="initialDataSize"/> is greater than zero. /// </summary> /// <param name="storageLocation">Location of the stream.</param> /// <param name="initialDataSize">Initial data size of the stream (in bytes).</param> /// <returns>The stream, initialized.</returns> /// <remarks>The capacity of the stream will be rounded up to the nearest multiple of 64 bytes.</remarks> public Stream OpenOrCreate(string storageLocation, int initialDataSize) { lock (FileSystem) { return(TestStorageStream.OpenOrCreate(FileSystem, storageLocation, initialDataSize)); } }
/// <inheritdoc /> public Stream Open(string storageLocation) { lock (FileSystem) { return(TestStorageStream.OpenOrCreate(FileSystem, storageLocation, -1)); } }
} // << REALLY do not like this! public static TestStorageStream OpenOrCreate(ConcurrentDictionary <string, TestStorageStream> fileSystem, string location, int initialSizeInBytes) { TestStorageStream stream; if (!fileSystem.TryGetValue(location, out stream)) { if (initialSizeInBytes > 0) { stream = new TestStorageStream(fileSystem, location, initialSizeInBytes); } else { stream = new TestStorageStream(fileSystem, location); } if (!fileSystem.TryAdd(location, stream)) { throw new InvalidOperationException(); } } stream.Open(); return(stream); }