Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc comments to StreamDecorator #122

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions sources/OpenMcdf.Extensions/StreamDecorator.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace OpenMcdf.Extensions
{
/// <summary>
/// A wrapper class to present a <see cref="CFStream"/> as a <see cref="Stream"/>.
/// </summary>
public class StreamDecorator : Stream
{
private CFStream cfStream;
private long position = 0;

/// <summary>
/// Create a new <see cref="StreamDecorator"/> for the specified <seealso cref="CFStream"/>.
/// </summary>
/// <param name="cfstream">The <see cref="CFStream"/> being wrapped.</param>
public StreamDecorator(CFStream cfstream)
{
this.cfStream = cfstream;
}

/// <inheritdoc/>
public override bool CanRead
{
get { return true; }
}

/// <inheritdoc/>
public override bool CanSeek
{
get { return true; }
}

/// <inheritdoc/>
public override bool CanWrite
{
get { return true; }
}

/// <inheritdoc/>
public override void Flush()
{
// nothing to do;
}

/// <inheritdoc/>
public override long Length
{
get { return cfStream.Size; }
}

/// <inheritdoc/>
public override long Position
{
get
Expand All @@ -52,6 +63,7 @@ public override long Position
}
}

/// <inheritdoc/>
public override int Read(byte[] buffer, int offset, int count)
{
if (count > buffer.Length)
Expand All @@ -71,6 +83,7 @@ public override int Read(byte[] buffer, int offset, int count)
return count;
}

/// <inheritdoc/>
public override long Seek(long offset, SeekOrigin origin)
{
switch (origin)
Expand All @@ -91,17 +104,20 @@ public override long Seek(long offset, SeekOrigin origin)
return position;
}

/// <inheritdoc/>
public override void SetLength(long value)
{
this.cfStream.Resize(value);
}

/// <inheritdoc/>
public override void Write(byte[] buffer, int offset, int count)
{
this.cfStream.Write(buffer, position, offset, count);
position += count;
}

/// <inheritdoc/>
public override void Close()
{
// Do nothing
Expand Down