forked from EvilBeaver/OneScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ПотокВПамяти и начало рефакторинга потоков
- Loading branch information
1 parent
e8378e5
commit 1b2358c
Showing
6 changed files
with
406 additions
and
556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/ScriptEngine.HostedScript/Library/Binary/GenericStreamImpl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.CodeDom; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using ScriptEngine.Machine; | ||
|
||
namespace ScriptEngine.HostedScript.Library.Binary | ||
{ | ||
class GenericStreamImpl | ||
{ | ||
Stream _underlyingStream; | ||
|
||
public GenericStreamImpl(Stream stream) | ||
{ | ||
_underlyingStream = stream; | ||
} | ||
|
||
public void Write(BinaryDataBuffer buffer, int positionInBuffer, int number) | ||
{ | ||
buffer.ThrowIfReadonly(); | ||
_underlyingStream.Write(buffer.Bytes, positionInBuffer, number); | ||
} | ||
|
||
public void CopyTo(IValue targetStream, int bufferSize = 0) | ||
{ | ||
IStreamWrapper sw = targetStream.GetRawValue() as IStreamWrapper; | ||
if (sw == null) | ||
throw RuntimeException.InvalidArgumentType("targetStream"); | ||
|
||
var stream = sw.GetUnderlyingStream(); | ||
if (bufferSize == 0) | ||
_underlyingStream.CopyTo(stream); | ||
else | ||
_underlyingStream.CopyTo(stream, bufferSize); | ||
} | ||
|
||
public long Seek(int offset, StreamPositionEnum initialPosition = StreamPositionEnum.Begin) | ||
{ | ||
SeekOrigin origin; | ||
switch (initialPosition) | ||
{ | ||
case StreamPositionEnum.End: | ||
origin = SeekOrigin.End; | ||
break; | ||
case StreamPositionEnum.Current: | ||
origin = SeekOrigin.Current; | ||
break; | ||
default: | ||
origin = SeekOrigin.Begin; | ||
break; | ||
} | ||
|
||
return _underlyingStream.Seek(offset, origin); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.