diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-04-02 00:46:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-02 00:46:26 -0400 |
| commit | c4a9dd3d262c880b8499e2f9b564d9ead99a7a22 (patch) | |
| tree | 47077506324da6137d56e322299942ee6eeb9512 /Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/RandomAccessFile.cs | |
| parent | b3640fbc9a0f7fd4a1def4e3c2f8860feb0f6922 (diff) | |
| parent | 4a8960fc866143e7107a5bc41527db6c5581974f (diff) | |
Merge pull request #2562 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/RandomAccessFile.cs')
| -rw-r--r-- | Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/RandomAccessFile.cs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/RandomAccessFile.cs b/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/RandomAccessFile.cs new file mode 100644 index 000000000..bf3596212 --- /dev/null +++ b/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/RandomAccessFile.cs @@ -0,0 +1,87 @@ +using System; +using System.IO; + +namespace SharpCifs.Util.Sharpen +{ + public class RandomAccessFile + { + private FileStream _stream; + + public RandomAccessFile (FilePath file, string mode) : this(file.GetPath (), mode) + { + } + + public RandomAccessFile (string file, string mode) + { + if (mode.IndexOf ('w') != -1) + _stream = new FileStream (file, FileMode.OpenOrCreate, FileAccess.ReadWrite); + else + _stream = new FileStream (file, FileMode.Open, FileAccess.Read); + } + + public void Close () + { + //Stream.`Close` method deleted + //_stream.Close (); + _stream.Dispose(); + } + + public long GetFilePointer () + { + return _stream.Position; + } + + public long Length () + { + return _stream.Length; + } + + public int Read (byte[] buffer) + { + int r = _stream.Read (buffer, 0, buffer.Length); + return r > 0 ? r : -1; + } + + public int Read (byte[] buffer, int start, int size) + { + return _stream.Read (buffer, start, size); + } + + public void ReadFully (byte[] buffer, int start, int size) + { + while (size > 0) { + int num = _stream.Read (buffer, start, size); + if (num == 0) { + throw new EofException (); + } + size -= num; + start += num; + } + } + + public void Seek (long pos) + { + _stream.Position = pos; + } + + public void SetLength (long len) + { + _stream.SetLength (len); + } + + public void Write (int value) + { + _stream.Write (BitConverter.GetBytes (value), 0, 4); + } + + public void Write (byte[] buffer) + { + _stream.Write (buffer, 0, buffer.Length); + } + + public void Write (byte[] buffer, int start, int size) + { + _stream.Write (buffer, start, size); + } + } +} |
