forked from ExcelDataReader/ExcelDataReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeekErrorMemoryStream.cs
More file actions
56 lines (46 loc) · 1.12 KB
/
Copy pathSeekErrorMemoryStream.cs
File metadata and controls
56 lines (46 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
#if LEGACY
namespace Excel.Tests
#else
namespace ExcelDataReader.Tests
#endif
{
public class SeekErrorMemoryStream : MemoryStream
{
private bool canSeek = false;
private SeekErrorMemoryStream()
{
}
/// <summary>
/// Creates SeekErrorMemoryStream copy data from the source
/// </summary>
/// <param name="source"></param>
public static SeekErrorMemoryStream CreateFromStream(Stream source)
{
var forwardStream = new SeekErrorMemoryStream();
forwardStream.canSeek = true;
Helper.CopyStream(source, forwardStream);
forwardStream.Seek(0, SeekOrigin.Begin);
//now disable seek
forwardStream.canSeek = false;
return forwardStream;
}
public override long Seek(long offset, SeekOrigin loc)
{
if (canSeek)
return base.Seek(offset, loc);
//throw offset error to simuate problem we had with HttpInputStream
throw new ArgumentOutOfRangeException("offset");
}
public override bool CanSeek
{
get
{
return canSeek;
}
}
}
}