Here are the examples of the csharp api System.IO.MemoryStream.Write(byte[], int, int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2219 Examples
19
View Source File : Server.cs
License : MIT License
Project Creator : 1ZouLTReX1
License : MIT License
Project Creator : 1ZouLTReX1
public bool ReceiveOnce()
{
/*
* returns one message in a byte array which then get processed by the client
* one message may require serveral calls to '.Receive' function.
*/
// Receive the response from the remote device.
if (offset >= bytesRec)
{
if (SafeReceive(ref buffer, ref bytesRec, ref offset))
return false;
}
len = Globals.DeSerializeLenPrefix(buffer, offset);
offset += sizeof(int);
while (len > 0)
{
cut = Math.Min(len, bytesRec - offset);
ms.Write(buffer, offset, cut);
len -= cut;
offset += cut;
if (len > 0)
{
// The left over of the previous message.
if (SafeReceive(ref buffer, ref bytesRec, ref offset))
return false;
}
}
// Process one message from the stream.
data = ms.ToArray();
// Clear the buffer.
ms.SetLength(0);
// Process the new received message.
ProcessMessage(data);
return true;
}
19
View Source File : Client.cs
License : MIT License
Project Creator : 1ZouLTReX1
License : MIT License
Project Creator : 1ZouLTReX1
public Byte[] ReceiveOnce()
{
/*
* returns one message in a byte array which then get processed by the client
* one message may require serveral calls to '.Receive' function.
*/
// Receive the response from the remote device.
if (offset >= bytesRec)
{
if (SafeReceive(ref buffer, ref bytesRec, ref offset))
return null;
}
len = Globals.DeSerializeLenPrefix(buffer, offset);
offset += sizeof(int);
while (len > 0)
{
cut = Math.Min(len, bytesRec - offset);
ms.Write(buffer, offset, cut);
len -= cut;
offset += cut;
if (len > 0)
{
// The left over of the previous message.
if (SafeReceive(ref buffer, ref bytesRec, ref offset))
return null;
}
}
// Process one message from the stream.
data = ms.ToArray();
// Clear the buffer.
ms.SetLength(0);
return data;
}
19
View Source File : StreamSerializeTest.cs
License : MIT License
Project Creator : 1996v
License : MIT License
Project Creator : 1996v
public override void Write(byte[] buffer, int offset, int count)
{
this.stream.Write(buffer, offset, count);
}
19
View Source File : RedisWriter.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
public byte[] Prepare(RedisCommand command)
{
var parts = command.Command.Split(' ');
int length = parts.Length + command.Arguments.Length;
StringBuilder sb = new StringBuilder();
sb.Append(MultiBulk).Append(length).Append(EOL);
foreach (var part in parts)
sb.Append(Bulk).Append(_io.Encoding.GetByteCount(part)).Append(EOL).Append(part).Append(EOL);
MemoryStream ms = new MemoryStream();
var data = _io.Encoding.GetBytes(sb.ToString());
ms.Write(data, 0, data.Length);
foreach (var arg in command.Arguments)
{
if (arg != null && arg.GetType() == typeof(byte[]))
{
data = arg as byte[];
var data2 = _io.Encoding.GetBytes($"{Bulk}{data.Length}{EOL}");
ms.Write(data2, 0, data2.Length);
ms.Write(data, 0, data.Length);
ms.Write(new byte[] { 13, 10 }, 0, 2);
}
else
{
string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
data = _io.Encoding.GetBytes($"{Bulk}{_io.Encoding.GetByteCount(str)}{EOL}{str}{EOL}");
ms.Write(data, 0, data.Length);
}
//string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
//sb.Append(Bulk).Append(_io.Encoding.GetByteCount(str)).Append(EOL).Append(str).Append(EOL);
}
return ms.ToArray();
}
19
View Source File : RedisWriter.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
public byte[] Prepare(RedisCommand command)
{
var parts = command.Command.Split(' ');
int length = parts.Length + command.Arguments.Length;
StringBuilder sb = new StringBuilder();
sb.Append(MultiBulk).Append(length).Append(EOL);
foreach (var part in parts)
sb.Append(Bulk).Append(_io.Encoding.GetByteCount(part)).Append(EOL).Append(part).Append(EOL);
MemoryStream ms = new MemoryStream();
var data = _io.Encoding.GetBytes(sb.ToString());
ms.Write(data, 0, data.Length);
foreach (var arg in command.Arguments)
{
if (arg != null && arg.GetType() == typeof(byte[]))
{
data = arg as byte[];
var data2 = _io.Encoding.GetBytes($"{Bulk}{data.Length}{EOL}");
ms.Write(data2, 0, data2.Length);
ms.Write(data, 0, data.Length);
ms.Write(new byte[] { 13, 10 }, 0, 2);
}
else
{
string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
data = _io.Encoding.GetBytes($"{Bulk}{_io.Encoding.GetByteCount(str)}{EOL}{str}{EOL}");
ms.Write(data, 0, data.Length);
}
//string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
//sb.Append(Bulk).Append(_io.Encoding.GetByteCount(str)).Append(EOL).Append(str).Append(EOL);
}
return ms.ToArray();
}
19
View Source File : RedisPipeline.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
public T Write<T>(RedisCommand<T> command)
{
var data = _io.Writer.Prepare(command);
lock (_bufferLock)
{
_buffer.Write(data, 0, data.Length);
_parsers.Enqueue(() => command.Parse(_io.Reader));
}
return default(T);
}
19
View Source File : RedisIO.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
public Byte[] ReadAll()
{
var ns = _stream as NetworkStream;
if (ns != null)
{
using (var ms = new MemoryStream())
{
try
{
var data = new byte[1024];
while (ns.DataAvailable && ns.CanRead)
{
int numBytesRead = 0;
lock (_streamLock)
numBytesRead = ns.Read(data, 0, data.Length);
if (numBytesRead <= 0) break;
ms.Write(data, 0, numBytesRead);
if (numBytesRead < data.Length) break;
}
}
catch { }
return ms.ToArray();
}
}
var ss = _stream as SslStream;
if (ss != null)
{
using (var ms = new MemoryStream())
{
try
{
var data = new byte[1024];
while (ss.CanRead)
{
int numBytesRead = 0;
lock (_streamLock)
numBytesRead = ss.Read(data, 0, data.Length);
if (numBytesRead <= 0) break;
ms.Write(data, 0, numBytesRead);
if (numBytesRead < data.Length) break;
}
}
catch { }
return ms.ToArray();
}
}
return new byte[0];
}
19
View Source File : TemplateEngin.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
public static byte[] ReadFile(string path) {
if (File.Exists(path)) {
string destFileName = Path.GetTempFileName();
File.Copy(path, destFileName, true);
int read = 0;
byte[] data = new byte[1024];
using (MemoryStream ms = new MemoryStream()) {
using (FileStream fs = new FileStream(destFileName, FileMode.OpenOrCreate, FileAccess.Read)) {
do {
read = fs.Read(data, 0, data.Length);
if (read <= 0) break;
ms.Write(data, 0, read);
} while (true);
}
File.Delete(destFileName);
data = ms.ToArray();
}
return data;
}
return new byte[] { };
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
public void WriteLittleEndian32(int value)
{
base.Write(BitConverter.GetBytes(value), 0, 4);
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
public void WriteString(string sString, bool bQuiet)
{
byte[] bytes = ASCIIEncoding.GetBytes(sString, bQuiet);
this.Write(bytes, 0, bytes.Length);
}
19
View Source File : HttpClient.cs
License : GNU Affero General Public License v3.0
Project Creator : 3drepo
License : GNU Affero General Public License v3.0
Project Creator : 3drepo
protected virtual Stream HttpGetURI(string uri, int tries = 1)
{
AppendApiKey(ref uri);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Proxy = proxy;
request.Method = "GET";
//request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.ReadWriteTimeout = timeout_ms;
request.Timeout = timeout_ms;
request.CookieContainer = cookies;
Console.WriteLine("GET " + uri + " TRY: " + tries);
try
{
MemoryStream memStream;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
memStream = new MemoryStream();
byte[] buffer = new byte[1024];
int byteCount;
int total = 0;
var ns = response.GetResponseStream();
do
{
byteCount = ns.Read(buffer, 0, buffer.Length);
memStream.Write(buffer, 0, byteCount);
total += byteCount;
} while (byteCount > 0);
request.Abort();
}
return memStream;
}
catch (WebException)
{
if (--tries == 0)
throw;
return HttpGetURI(uri, tries);
}
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
public void copyToByteArray(RdpPacket packet)
{
byte[] buffer = new byte[packet.Length];
packet.Position = 0L;
packet.Read(buffer, 0, (int) packet.Length);
this.Write(buffer, 0, buffer.Length);
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
private void ReadFromSocket(int lengthRequired)
{
if (this.m_Socket == null)
{
throw new IOException("RdpPacket - Overrun!");
}
int count = this.m_Socket.Receive(this.m_Buffer, this.m_Buffer.Length);
if (count <= 0)
{
throw new IOException("RdpPacket - Overrun!");
}
lengthRequired -= count;
if (lengthRequired > 0)
{
throw new IOException("RdpPacket - Overrun!");
}
long position = this.Position;
this.Write(this.m_Buffer, 0, count);
this.Position = position;
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
public void WriteBigEndian16(short Value)
{
base.Write(this.Reverse(BitConverter.GetBytes(Value)), 0, 2);
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
public void WriteLittleEndian16(short Value)
{
base.Write(BitConverter.GetBytes(Value), 0, 2);
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
public void WriteLittleEndian16(ushort Value)
{
base.Write(BitConverter.GetBytes(Value), 0, 2);
}
19
View Source File : RdpPacket.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent
public void WriteLittleEndian32(uint value)
{
base.Write(BitConverter.GetBytes(value), 0, 4);
}
19
View Source File : ObjectSerializationExtension.cs
License : MIT License
Project Creator : 734843327
License : MIT License
Project Creator : 734843327
public static T Deserialize<T>(this byte[] byteArray) where T : clreplaced
{
if (byteArray == null)
{
return null;
}
using (var memStream = new MemoryStream())
{
var binForm = new BinaryFormatter();
memStream.Write(byteArray, 0, byteArray.Length);
memStream.Seek(0, SeekOrigin.Begin);
var obj = (T)binForm.Deserialize(memStream);
return obj;
}
}
19
View Source File : BundleFile.cs
License : MIT License
Project Creator : 91Act
License : MIT License
Project Creator : 91Act
private void ReadFormat6(EndianBinaryReader b_Stream, bool padding = false)
{
var bundleSize = b_Stream.ReadInt64();
int compressedSize = b_Stream.ReadInt32();
int uncompressedSize = b_Stream.ReadInt32();
int flag = b_Stream.ReadInt32();
if (padding)
b_Stream.ReadByte();
byte[] blocksInfoBytes;
if ((flag & 0x80) != 0)//at end of file
{
var position = b_Stream.Position;
b_Stream.Position = b_Stream.BaseStream.Length - compressedSize;
blocksInfoBytes = b_Stream.ReadBytes(compressedSize);
b_Stream.Position = position;
}
else
{
blocksInfoBytes = b_Stream.ReadBytes(compressedSize);
}
MemoryStream blocksInfoStream;
switch (flag & 0x3F)
{
default://None
{
blocksInfoStream = new MemoryStream(blocksInfoBytes);
break;
}
case 1://LZMA
{
blocksInfoStream = SevenZipHelper.StreamDecompress(new MemoryStream(blocksInfoBytes));
break;
}
case 2://LZ4
case 3://LZ4HC
{
byte[] uncompressedBytes = new byte[uncompressedSize];
using (var mstream = new MemoryStream(blocksInfoBytes))
{
var decoder = new Lz4DecoderStream(mstream);
decoder.Read(uncompressedBytes, 0, uncompressedSize);
decoder.Dispose();
}
blocksInfoStream = new MemoryStream(uncompressedBytes);
break;
}
//case 4:LZHAM?
}
using (var blocksInfo = new EndianBinaryReader(blocksInfoStream))
{
blocksInfo.Position = 0x10;
int blockcount = blocksInfo.ReadInt32();
var replacedetsDataStream = new MemoryStream();
for (int i = 0; i < blockcount; i++)
{
uncompressedSize = blocksInfo.ReadInt32();
compressedSize = blocksInfo.ReadInt32();
flag = blocksInfo.ReadInt16();
var compressedBytes = b_Stream.ReadBytes(compressedSize);
switch (flag & 0x3F)
{
default://None
{
replacedetsDataStream.Write(compressedBytes, 0, compressedSize);
break;
}
case 1://LZMA
{
var uncompressedBytes = new byte[uncompressedSize];
using (var mstream = new MemoryStream(compressedBytes))
{
var decoder = SevenZipHelper.StreamDecompress(mstream, uncompressedSize);
decoder.Read(uncompressedBytes, 0, uncompressedSize);
decoder.Dispose();
}
replacedetsDataStream.Write(uncompressedBytes, 0, uncompressedSize);
break;
}
case 2://LZ4
case 3://LZ4HC
{
var uncompressedBytes = new byte[uncompressedSize];
using (var mstream = new MemoryStream(compressedBytes))
{
var decoder = new Lz4DecoderStream(mstream);
decoder.Read(uncompressedBytes, 0, uncompressedSize);
decoder.Dispose();
}
replacedetsDataStream.Write(uncompressedBytes, 0, uncompressedSize);
break;
}
//case 4:LZHAM?
}
}
using (var replacedetsData = new EndianBinaryReader(replacedetsDataStream))
{
var entryinfo_count = blocksInfo.ReadInt32();
for (int i = 0; i < entryinfo_count; i++)
{
var memFile = new MemoryreplacedetsFile();
var entryinfo_offset = blocksInfo.ReadInt64();
var entryinfo_size = blocksInfo.ReadInt64();
var unknown = blocksInfo.ReadInt32();
memFile.fileName = blocksInfo.ReadStringToNull();
replacedetsData.Position = entryinfo_offset;
var buffer = replacedetsData.ReadBytes((int)entryinfo_size);
memFile.memStream = new MemoryStream(buffer);
MemoryreplacedetsFileList.Add(memFile);
}
}
}
}
19
View Source File : BundleFile.cs
License : MIT License
Project Creator : 91Act
License : MIT License
Project Creator : 91Act
private void ReadFormat6(EndianBinaryReader b_Stream, bool padding = false)
{
var bundleSize = b_Stream.ReadInt64();
int compressedSize = b_Stream.ReadInt32();
int uncompressedSize = b_Stream.ReadInt32();
int flag = b_Stream.ReadInt32();
if (padding)
b_Stream.ReadByte();
byte[] blocksInfoBytes;
if ((flag & 0x80) != 0)//at end of file
{
var position = b_Stream.Position;
b_Stream.Position = b_Stream.BaseStream.Length - compressedSize;
blocksInfoBytes = b_Stream.ReadBytes(compressedSize);
b_Stream.Position = position;
}
else
{
blocksInfoBytes = b_Stream.ReadBytes(compressedSize);
}
MemoryStream blocksInfoStream;
switch (flag & 0x3F)
{
default://None
{
blocksInfoStream = new MemoryStream(blocksInfoBytes);
break;
}
case 1://LZMA
{
blocksInfoStream = SevenZipHelper.StreamDecompress(new MemoryStream(blocksInfoBytes));
break;
}
case 2://LZ4
case 3://LZ4HC
{
byte[] uncompressedBytes = new byte[uncompressedSize];
using (var mstream = new MemoryStream(blocksInfoBytes))
{
var decoder = new Lz4DecoderStream(mstream);
decoder.Read(uncompressedBytes, 0, uncompressedSize);
decoder.Dispose();
}
blocksInfoStream = new MemoryStream(uncompressedBytes);
break;
}
//case 4:LZHAM?
}
using (var blocksInfo = new EndianBinaryReader(blocksInfoStream))
{
blocksInfo.Position = 0x10;
int blockcount = blocksInfo.ReadInt32();
var replacedetsDataStream = new MemoryStream();
for (int i = 0; i < blockcount; i++)
{
uncompressedSize = blocksInfo.ReadInt32();
compressedSize = blocksInfo.ReadInt32();
flag = blocksInfo.ReadInt16();
var compressedBytes = b_Stream.ReadBytes(compressedSize);
switch (flag & 0x3F)
{
default://None
{
replacedetsDataStream.Write(compressedBytes, 0, compressedSize);
break;
}
case 1://LZMA
{
var uncompressedBytes = new byte[uncompressedSize];
using (var mstream = new MemoryStream(compressedBytes))
{
var decoder = SevenZipHelper.StreamDecompress(mstream, uncompressedSize);
decoder.Read(uncompressedBytes, 0, uncompressedSize);
decoder.Dispose();
}
replacedetsDataStream.Write(uncompressedBytes, 0, uncompressedSize);
break;
}
case 2://LZ4
case 3://LZ4HC
{
var uncompressedBytes = new byte[uncompressedSize];
using (var mstream = new MemoryStream(compressedBytes))
{
var decoder = new Lz4DecoderStream(mstream);
decoder.Read(uncompressedBytes, 0, uncompressedSize);
decoder.Dispose();
}
replacedetsDataStream.Write(uncompressedBytes, 0, uncompressedSize);
break;
}
//case 4:LZHAM?
}
}
using (var replacedetsData = new EndianBinaryReader(replacedetsDataStream))
{
var entryinfo_count = blocksInfo.ReadInt32();
for (int i = 0; i < entryinfo_count; i++)
{
var memFile = new MemoryreplacedetsFile();
var entryinfo_offset = blocksInfo.ReadInt64();
var entryinfo_size = blocksInfo.ReadInt64();
var unknown = blocksInfo.ReadInt32();
memFile.fileName = blocksInfo.ReadStringToNull();
replacedetsData.Position = entryinfo_offset;
var buffer = replacedetsData.ReadBytes((int)entryinfo_size);
memFile.memStream = new MemoryStream(buffer);
MemoryreplacedetsFileList.Add(memFile);
}
}
}
}
19
View Source File : WavUtility.cs
License : GNU General Public License v3.0
Project Creator : a2659802
License : GNU General Public License v3.0
Project Creator : a2659802
private static byte[] ConvertAudioClipDataToInt16ByteArray(float[] data)
{
MemoryStream dataStream = new MemoryStream();
int x = sizeof(Int16);
Int16 maxValue = Int16.MaxValue;
int i = 0;
while (i < data.Length)
{
dataStream.Write(BitConverter.GetBytes(Convert.ToInt16(data[i] * maxValue)), 0, x);
++i;
}
byte[] bytes = dataStream.ToArray();
// Validate converted bytes
Debug.replacedertFormat(data.Length * x == bytes.Length, "Unexpected float[] to Int16 to byte[] size: {0} == {1}", data.Length * x, bytes.Length);
dataStream.Dispose();
return bytes;
}
19
View Source File : WavUtility.cs
License : GNU General Public License v3.0
Project Creator : a2659802
License : GNU General Public License v3.0
Project Creator : a2659802
private static int WriteBytesToMemoryStream(ref MemoryStream stream, byte[] bytes, string tag = "")
{
int count = bytes.Length;
stream.Write(bytes, 0, count);
//Debug.LogFormat ("WAV:{0} wrote {1} bytes.", tag, count);
return count;
}
19
View Source File : AudioOut.cs
License : Apache License 2.0
Project Creator : ac87
License : Apache License 2.0
Project Creator : ac87
public void AddBytesToPlay(byte[] bytes)
{
if (_waveOut == null)
{
_waveOut = new WaveOut();
_waveOut.PlaybackStopped += (sender, args) =>
{
_waveStream.Dispose();
_ms.Dispose();
_ms = null;
OnAudioPlaybackStateChanged?.Invoke(false);
};
}
if (_ms == null)
_ms = new MemoryStream();
_ms.Write(bytes, 0, bytes.Length);
}
19
View Source File : NetworkSession.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
private void DoRequestForRetransmission(uint rcvdSeq)
{
var desiredSeq = lastReceivedPacketSequence + 1;
List<uint> needSeq = new List<uint>();
needSeq.Add(desiredSeq);
uint bottom = desiredSeq + 1;
if (rcvdSeq < bottom || rcvdSeq - bottom > CryptoSystem.MaximumEffortLevel)
{
session.Terminate(SessionTerminationReason.AbnormalSequenceReceived);
return;
}
uint seqIdCount = 1;
for (uint a = bottom; a < rcvdSeq; a++)
{
if (!outOfOrderPackets.ContainsKey(a))
{
needSeq.Add(a);
seqIdCount++;
if (seqIdCount >= MaxNumNakSeqIds)
{
break;
}
}
}
ServerPacket reqPacket = new ServerPacket();
byte[] reqData = new byte[4 + (needSeq.Count * 4)];
MemoryStream msReqData = new MemoryStream(reqData, 0, reqData.Length, true, true);
msReqData.Write(BitConverter.GetBytes((uint)needSeq.Count), 0, 4);
needSeq.ForEach(k => msReqData.Write(BitConverter.GetBytes(k), 0, 4));
reqPacket.Data = msReqData;
reqPacket.Header.Flags = PacketHeaderFlags.RequestRetransmit;
EnqueueSend(reqPacket);
LastRequestForRetransmitTime = DateTime.UtcNow;
packetLog.DebugFormat("[{0}] Requested retransmit of {1}", session.LoggingIdentifier, needSeq.Select(k => k.ToString()).Aggregate((a, b) => a + ", " + b));
NetworkStatistics.S2C_RequestsForRetransmit_Aggregate_Increment();
}
19
View Source File : MainActivity.cs
License : MIT License
Project Creator : adamped
License : MIT License
Project Creator : adamped
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Forms.Init(this, bundle);
// Copy image from replacedets and place in DataDirectory on Android.
using (var stream = replacedets.OpenFd("image.upng"))
using (var readStream = replacedets.Open("image.upng"))
using (var memoryStream = new MemoryStream())
{
byte[] buffer = new byte[stream.Length];
int read;
while ((read = readStream.Read(buffer, 0, buffer.Length)) > 0)
{
memoryStream.Write(buffer, 0, read);
}
var data = memoryStream.ToArray();
var path = Path.Combine(Environment.ExternalStorageDirectory.AbsolutePath, "image.png");
System.IO.File.WriteAllBytes(path, data);
}
DependencyService.Register<FileStore>();
DependencyService.Register<Share>();
LoadApplication(new App());
}
19
View Source File : FormattingOptionsTests.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
[TestCase(ElementKind.Attribute, "changed_obsolete", "Attribute_obsolete")]
[TestCase(ElementKind.Clreplaced, "changed_foo", "Clreplaced_foo")]
[TestCase(ElementKind.Constructor, "changed_foo", "Constructor_foo")]
[TestCase(ElementKind.Delegate, "changed_del", "Delegate_del")]
[TestCase(ElementKind.Enum, "changed_E", "Enum_E")]
[TestCase(ElementKind.Event, "changed_evt", "Event_evt")]
[TestCase(ElementKind.Field, "changed_field", "Field_field")]
[TestCase(ElementKind.Interface, "changed_I", "Interface_I")]
[TestCase(ElementKind.Label, "changed_", "Label")]
[TestCase(ElementKind.Method, "changed_bar", "Method_bar")]
[TestCase(ElementKind.Parameter, "changed_param1", "Parameter_param1")]
[TestCase(ElementKind.Property, "changed_prop1", "Property_prop1")]
[TestCase(ElementKind.Struct, "changed_S", "Struct_S")]
[TestCase(ElementKind.StaticConstructor, "changed_foo", "StaticConstructor_foo")]
[TestCase(ElementKind.GenericInstance, "changed_gen", "GenericInstance_gen")]
[TestCase(ElementKind.GenericParameter, "changed_gP", "GenericParameter_gP")]
[TestCase(ElementKind.IL, "changed_bar", "IL_bar")]
[TestCase(ElementKind.LocalVariable, "changed_local1", "LocalVariable_local1")]
public void ElementKind_Is_Used(ElementKind elementKind, string expected, string notExpected)
{
const string source = "using System; public delegate void Del(); clreplaced Foo { static Foo() {} public Foo() {} void Gen<GP>() {} [Obsolete] int Obsolete; event Action Evt; public void Bar(int param1) { int local1 = 0; if (param1 == local1) {} Gen<int>();} int field; int Prop1 {get;set;} } struct S {} enum E {} interface I {}";
prefixes[elementKind] = "changed";
var nameStrategy = new DefaultNameStrategy(NamingOptions.All, prefixes);
var memoryStream = new MemoryStream();
memoryStream.Write(System.Text.Encoding.ASCII.GetBytes(source));
memoryStream.Position = 0;
var cecilified = Cecilifier.Process(memoryStream, new CecilifierOptions { References = Utils.GetTrustedreplacedembliesPath(), Naming = nameStrategy }).GeneratedCode.ReadToEnd();
replacedert.That(cecilified, Does.Match($"\\b{expected}"), $"{elementKind} prefix not applied.");
replacedert.That(cecilified, Does.Not.Match($"\\b{notExpected}"), $"{elementKind} prefix not applied.");
}
19
View Source File : MappingTests.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
private static CecilifierResult RunCecilifier(string code)
{
var nameStrategy = new DefaultNameStrategy();
var memoryStream = new MemoryStream();
memoryStream.Write(System.Text.Encoding.ASCII.GetBytes(code));
memoryStream.Position = 0;
return Cecilifier.Process(memoryStream, new CecilifierOptions { References = Utils.GetTrustedreplacedembliesPath(), Naming = nameStrategy });
}
19
View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens
License : MIT License
Project Creator : adrianstevens
static byte[] ReadBuffer(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (var ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
19
View Source File : FormattingOptionsTests.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
[Test, Combinatorial]
public void Casing_Setting_Is_Respected([Values] ElementKind elementKind, [Values] bool camelCasing)
{
if (elementKind == ElementKind.Label && !camelCasing)
{
replacedert.Ignore("as of Aug/2021 all created labels are camelCase.");
return;
}
const string source = "using System; public delegate void TestDelegate(); clreplaced TestClreplaced { static TestClreplaced() {} public TestClreplaced() {} void Gen<TestGenericParameter>() {} [Obsolete] int TestAttribute; event Action TestEvent; public void Bar(int TestParameter) { int local1 = 0; if (TestParameter == local1) {} Gen<int>(); } int TestField; int TestProperty {get;set;} } struct TestStruct {} enum TestEnum {} interface TestInterface {}";
var namingOptions = NamingOptions.All;
var casingValidation = "a-z";
if (!camelCasing)
{
namingOptions &= ~NamingOptions.CamelCaseElementNames;
casingValidation = "A-Z";
}
var nameStrategy = new DefaultNameStrategy(namingOptions, prefixes);
var memoryStream = new MemoryStream();
memoryStream.Write(System.Text.Encoding.ASCII.GetBytes(source));
memoryStream.Position = 0;
var cecilified = Cecilifier.Process(memoryStream, new CecilifierOptions { References = Utils.GetTrustedreplacedembliesPath(), Naming = nameStrategy }).GeneratedCode.ReadToEnd();
replacedert.That(cecilified, Does.Match($"{elementKind}_[{casingValidation}][a-zA-Z]+"), "Casing");
}
19
View Source File : CecilifierUnitTestBase.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
protected static CecilifierResult RunCecilifier(string code)
{
var nameStrategy = new DefaultNameStrategy();
var memoryStream = new MemoryStream();
memoryStream.Write(System.Text.Encoding.ASCII.GetBytes(code));
memoryStream.Position = 0;
return Cecilifier.Process(memoryStream, new CecilifierOptions { References = Utils.GetTrustedreplacedembliesPath(), Naming = nameStrategy });
}
19
View Source File : ReviewAvatarsHandler.cs
License : Apache License 2.0
Project Creator : advanced-cms
License : Apache License 2.0
Project Creator : advanced-cms
public void ProcessRequest(HttpContext context)
{
var userName = context.Request.QueryString.Get("userName");
if (string.IsNullOrWhiteSpace(userName))
{
context.Response.StatusCode = 404;
return;
}
userName = HttpUtility.UrlDecode(userName);
using (var memoryStream = new MemoryStream())
{
var customAvatar = _customAvatarResolver.GetImage(userName);
if (customAvatar != null)
{
memoryStream.Write(customAvatar, 0, customAvatar.Length);
}
else
{
var identicon = _identiconGenerator.CreateIdenticon(userName, 100);
var encoder = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == ImageFormat.Jpeg.Guid);
var encParams = new EncoderParameters { Param = new[] { new EncoderParameter(Encoder.Quality, 90L) } };
identicon.Save(memoryStream, encoder, encParams);
}
var bytesInStream = memoryStream.ToArray();
context.Response.Clear();
context.Response.ContentType = "Image/jpeg";
context.Response.BinaryWrite(bytesInStream);
// context.Response.End() affects the cache
//context.Response.End();
}
}
19
View Source File : HttpHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
static WebList Http_DownSteam(HttpWebResponse response, Encoding encoding)
{
WebList _web = new WebList
{
Encoding = encoding,
StatusCode = (int)response.StatusCode,
Type = response.ContentType,
AbsoluteUri = response.ResponseUri.AbsoluteUri
};
string header = "";
foreach (string str in response.Headers.AllKeys)
{
if (str == "Set-Cookie")
{
_web.SetCookie = response.Headers[str];
}
else if (str == "Location")
{
_web.Location = response.Headers[str];
}
header = header + str + ":" + response.Headers[str] + "\r\n";
}
string cookie = "";
foreach (Cookie str in response.Cookies)
{
cookie = cookie + str.Name + "=" + str.Value + ";";
}
_web.Header = header;
_web.Cookie = cookie;
#region 下载流
using (Stream stream = response.GetResponseStream())
{
using (MemoryStream file = new MemoryStream())
{
int _value = 0;
byte[] _cache = new byte[1024];
int osize = stream.Read(_cache, 0, 1024);
while (osize > 0)
{
_value += osize;
file.Write(_cache, 0, osize);
osize = stream.Read(_cache, 0, 1024);
}
file.Seek(0, SeekOrigin.Begin);
byte[] _byte = new byte[_value];
file.Read(_byte, 0, _value);
file.Seek(0, SeekOrigin.Begin);
string fileclreplaced = GetFileClreplaced(file);
if (fileclreplaced == "31139")
{
//_web.OriginalSize = _byte.Length;
_web.Byte = Decompress(_byte);
}
else
{
_web.Byte = _byte;
}
}
}
#endregion
return _web;
}
19
View Source File : HttpHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
static byte[] Decompress(byte[] data)
{
try
{
var ms = new MemoryStream(data);
var zip = new GZipStream(ms, CompressionMode.Decompress, true);
var msreader = new MemoryStream();
var buffer = new byte[0x1000];
while (true)
{
var reader = zip.Read(buffer, 0, buffer.Length);
if (reader <= 0)
{
break;
}
msreader.Write(buffer, 0, reader);
}
zip.Close();
ms.Close();
msreader.Position = 0;
buffer = msreader.ToArray();
msreader.Close();
return buffer;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
19
View Source File : AssetsCustomAvatarResolver.cs
License : Apache License 2.0
Project Creator : advanced-cms
License : Apache License 2.0
Project Creator : advanced-cms
public static byte[] ToArray(Stream input)
{
var buffer = new byte[16 * 1024];
using (var ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
19
View Source File : StringCompressor.cs
License : GNU General Public License v3.0
Project Creator : aelariane
License : GNU General Public License v3.0
Project Creator : aelariane
public static string DecompressString(string compressedText)
{
byte[] array = Convert.FromBase64String(compressedText);
string @string;
using (MemoryStream memoryStream = new MemoryStream())
{
int num = BitConverter.ToInt32(array, 0);
memoryStream.Write(array, 4, array.Length - 4);
byte[] array2 = new byte[num];
memoryStream.Position = 0L;
using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
{
gzipStream.Read(array2, 0, array2.Length);
}
@string = Encoding.UTF8.GetString(array2);
}
return @string;
}
19
View Source File : MemoryIterator.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
public bool Write(long offset, SeekOrigin origin, byte[] data)
{
if (data == null)
{
throw new ArgumentNullException("Parameter 'data' cannot be null");
}
try
{
this._base.Seek(offset, origin);
this._base.Write(data, 0, data.Length);
return true;
}
catch (Exception exception)
{
return this.SetLastError(exception);
}
}
19
View Source File : MemoryIterator.cs
License : Apache License 2.0
Project Creator : aequabit
License : Apache License 2.0
Project Creator : aequabit
public bool Write<TSource>(long offset, SeekOrigin origin, TSource data) where TSource: struct
{
try
{
this._base.Seek(offset, origin);
byte[] buffer = null;
if (!this._ubuffer.Translate<TSource>(data, out buffer))
{
throw this._ubuffer.GetLastError();
}
this._base.Write(buffer, 0, buffer.Length);
return true;
}
catch (Exception exception)
{
return this.SetLastError(exception);
}
}
19
View Source File : TsonSerializerBase.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void WriteStringValue(string value)
{
if (value == null)
{
WriteLen(0);
}
else if (value == string.Empty)
{
WriteLen(-1);
}
else
{
var by = value.ToUtf8Bytes();
WriteLen(by.Length);
Stream.Write(by, 0, by.Length);
}
}
19
View Source File : TsonSerializerBase.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void WriteGuidValue(Guid value)
{
Stream.Write(value.ToByteArray(), 0, 16);
}
19
View Source File : TsonSerializerBase.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void WriteValue(string value)
{
if (value == null)
{
WriteLen(0);
}
else if (value == string.Empty)
{
WriteLen(-1);
}
else
{
var by = value.ToUtf8Bytes();
WriteLen(by.Length);
Stream.Write(by, 0, by.Length);
}
}
19
View Source File : TsonSerializerBase.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void WriteValue(Guid value)
{
Stream.Write(value.ToByteArray(), 0, 16);
}
19
View Source File : FakeStream.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public override void Write(byte[] buffer, int offset, int count)
{
lock (_responses)
{
byte[] message = new byte[count];
Buffer.BlockCopy(buffer, offset, message, 0, count);
_messages.Enqueue(message);
base.Write(buffer, offset, count);
byte[] next = _responses.Dequeue();
base.Write(next, 0, next.Length);
Position -= next.Length;
}
}
19
View Source File : RedisWriter.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
byte[] Prepare(RedisCommand command)
{
var parts = command.Command.Split(' ');
int length = parts.Length + command.Arguments.Length;
StringBuilder sb = new StringBuilder();
sb.Append(MultiBulk).Append(length).Append(EOL);
foreach (var part in parts)
sb.Append(Bulk).Append(_io.Encoding.GetByteCount(part)).Append(EOL).Append(part).Append(EOL);
MemoryStream ms = new MemoryStream();
var data = _io.Encoding.GetBytes(sb.ToString());
ms.Write(data, 0, data.Length);
foreach (var arg in command.Arguments)
{
if (arg.GetType() == typeof(byte[])) {
data = arg as byte[];
var data2 = _io.Encoding.GetBytes($"{Bulk}{data.Length}{EOL}");
ms.Write(data2, 0, data2.Length);
ms.Write(data, 0, data.Length);
ms.Write(new byte[] { 13, 10 }, 0, 2);
} else {
string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
data = _io.Encoding.GetBytes($"{Bulk}{_io.Encoding.GetByteCount(str)}{EOL}{str}{EOL}");
ms.Write(data, 0, data.Length);
}
//string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
//sb.Append(Bulk).Append(_io.Encoding.GetByteCount(str)).Append(EOL).Append(str).Append(EOL);
}
return ms.ToArray();
}
19
View Source File : RedisWriter.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
byte[] Prepare(RedisCommand command)
{
var parts = command.Command.Split(' ');
int length = parts.Length + command.Arguments.Length;
StringBuilder sb = new StringBuilder();
sb.Append(MultiBulk).Append(length).Append(EOL);
foreach (var part in parts)
sb.Append(Bulk).Append(_io.Encoding.GetByteCount(part)).Append(EOL).Append(part).Append(EOL);
MemoryStream ms = new MemoryStream();
var data = _io.Encoding.GetBytes(sb.ToString());
ms.Write(data, 0, data.Length);
foreach (var arg in command.Arguments)
{
if (arg.GetType() == typeof(byte[])) {
data = arg as byte[];
var data2 = _io.Encoding.GetBytes($"{Bulk}{data.Length}{EOL}");
ms.Write(data2, 0, data2.Length);
ms.Write(data, 0, data.Length);
ms.Write(new byte[] { 13, 10 }, 0, 2);
} else {
string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
data = _io.Encoding.GetBytes($"{Bulk}{_io.Encoding.GetByteCount(str)}{EOL}{str}{EOL}");
ms.Write(data, 0, data.Length);
}
//string str = String.Format(CultureInfo.InvariantCulture, "{0}", arg);
//sb.Append(Bulk).Append(_io.Encoding.GetByteCount(str)).Append(EOL).Append(str).Append(EOL);
}
return ms.ToArray();
}
19
View Source File : WebSocketNotify.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
private async Task EchoLoop()
{
var buffer = new byte[BufferSize];
var seg = new ArraySegment<byte>(buffer);
while (this.socket.State == WebSocketState.Open)
{
try
{
string value;
using (var mem = new MemoryStream())
{
var incoming = await this.socket.ReceiveAsync(seg, CancellationToken.None);
if (!incoming.EndOfMessage)
{
await socket.CloseAsync(WebSocketCloseStatus.MessageTooBig, "Message too big", CancellationToken.None);
break;
}
if (incoming.Count == 0)
continue;
mem.Write(seg.Array, 0, incoming.Count);
mem.Flush();
mem.Position = 0;
TextReader reader = new StreamReader(mem);
value = reader.ReadToEnd();
}
if (string.IsNullOrEmpty(value) || value.Length <= 1)
continue;
string replacedle = value.Length == 0 ? "" : value.Substring(1);
if (value[0] == '+')
{
if (!Subscriber.Contains(replacedle))
Subscriber.Add(replacedle);
}
else if (value[0] == '-')
{
Subscriber.Remove(replacedle);
}
}
catch (WebSocketException)
{
break;
}
catch (Exception)
{
break;
}
}
}
19
View Source File : AudioPlayer.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
private void Filler(IntPtr data, int size)
{
int blockCount = _wave.BlockCount;
byte[] b = new byte[size];
if (_file != null && (_looped || _lastBlock < blockCount))
{
MemoryStream ms = new MemoryStream();
if (_leftOverBuffer != null)
{
ms.Write(_leftOverBuffer, 0, _leftOverBuffer.Length);
}
while (ms.Position < size)
{
_lastBlock++;
if (_lastBlock >= blockCount)
{
if (!_looped)
{
while(ms.Position < size)
{
ms.WriteByte(0);
}
break;
}
else
{
_lastBlock = 0;
_state = new DviAdpcmDecoder.AdpcmState();
}
}
_file.SoundBank.ExportWaveBlockAsPCM(_wave.Index, _lastBlock, ref _state, _file.Stream, ms);
}
int extraData = (int)(ms.Position - size);
ms.Seek(0, SeekOrigin.Begin);
ms.Read(b, 0, size);
if (extraData > 0)
{
_leftOverBuffer = new byte[extraData];
ms.Read(_leftOverBuffer, 0, extraData);
}
else
{
_leftOverBuffer = null;
}
}
else
{
for (int i = 0; i < b.Length; i++)
{
b[i] = 0;
}
}
System.Runtime.InteropServices.Marshal.Copy(b, 0, data, size);
}
19
View Source File : ResourceFile.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
public void Write(Stream data)
{
var bw = new BinaryWriter(data);
if (SystemMemSize != _systemMemData.Length || GraphicsMemSize != _graphicsMemData.Length)
{
_header.SetMemSizes(SystemMemSize, GraphicsMemSize);
}
_header.Write( bw );
var ms = new MemoryStream();
ms.Write(_systemMemData, 0, _systemMemData.Length);
ms.Write(new byte[SystemMemSize - _systemMemData.Length], 0, SystemMemSize - _systemMemData.Length);
ms.Write(_graphicsMemData, 0, _graphicsMemData.Length);
ms.Write(new byte[GraphicsMemSize - _graphicsMemData.Length], 0, GraphicsMemSize - _graphicsMemData.Length);
ms.Seek(0, SeekOrigin.Begin);
var msCompress = new MemoryStream();
_codec.Compress( ms, msCompress );
bw.Write(msCompress.ToArray());
ms.Close();
msCompress.Close();
bw.Flush();
}
19
View Source File : IconFile.cs
License : MIT License
Project Creator : ahopper
License : MIT License
Project Creator : ahopper
static public void SaveToICNS(Drawing drawing, List<int> sizes, string filename)
{
int headerLen = 8;
int fileLen = headerLen;
using (var icoStream = new MemoryStream())
{
icoStream.WriteByte(0x69);
icoStream.WriteByte(0x63);
icoStream.WriteByte(0x6e);
icoStream.WriteByte(0x73);
icoStream.Position = headerLen;
for (int i = 0; i < sizes.Count; i++)
{
var start = icoStream.Position;
icoStream.Position += 8;
SaveDrawing(drawing, sizes[i], icoStream);
var end = icoStream.Position;
int pngLen = (int)(end - start);
fileLen += pngLen;
icoStream.Position = start;
string iconType;
switch(sizes[i])
{
case 16: iconType = "icp4"; break;
case 32: iconType = "icp5"; break;
case 64: iconType = "icp6"; break;
case 128: iconType = "ic07"; break;
case 256: iconType = "ic08"; break;
case 512: iconType = "ic09"; break;
default: throw new Exception($"Unsupported icns size {sizes[i]}");
}
icoStream.Write(ASCIIEncoding.ASCII.GetBytes(iconType));
icoStream.WriteByte((byte)(pngLen >> 24));
icoStream.WriteByte((byte)((pngLen >> 16) & 0xff));
icoStream.WriteByte((byte)((pngLen >> 8) & 0xff));
icoStream.WriteByte((byte)(pngLen & 0xff));
icoStream.Position = end;
}
icoStream.Position = 4;
icoStream.WriteByte((byte)(fileLen >> 24));
icoStream.WriteByte((byte)((fileLen >> 16) & 0xff));
icoStream.WriteByte((byte)((fileLen >> 8) & 0xff));
icoStream.WriteByte((byte)(fileLen & 0xff));
using (var icoFile = File.Create(filename))
{
icoFile.Write(icoStream.GetBuffer(), 0, fileLen);
}
}
}
19
View Source File : BundleRecord.cs
License : GNU Affero General Public License v3.0
Project Creator : aianlinb
License : GNU Affero General Public License v3.0
Project Creator : aianlinb
public virtual void Save(string newPath = null, string originalPath = null)
{
if (newPath == null && originalPath == null && Bundle.path == null)
#pragma warning disable CA2208 // 正確地將引數例外狀況具現化
throw new ArgumentNullException();
var data = new MemoryStream();
foreach (var d in FileToAdd)
{
d.Key.Offset = (int)data.Position + Bundle.uncompressed_size;
data.Write(d.Value, 0, d.Key.Size);
}
UncompressedSize = (int)data.Length + Bundle.uncompressed_size;
FileToAdd.Clear();
if (newPath != null)
File.WriteAllBytes(newPath, Bundle.AppendAndSave(data, originalPath));
else if (originalPath != null)
File.WriteAllBytes(originalPath, Bundle.AppendAndSave(data, originalPath));
else
File.WriteAllBytes(Bundle.path, Bundle.AppendAndSave(data, originalPath));
}
19
View Source File : BundleRecord.cs
License : GNU Affero General Public License v3.0
Project Creator : aianlinb
License : GNU Affero General Public License v3.0
Project Creator : aianlinb
public virtual byte[] Save(BinaryReader br, long? Offset = null)
{
Read(br, Offset);
var data = new MemoryStream();
foreach (var (f, b) in FileToAdd)
{
f.Offset = (int)data.Position + Bundle.uncompressed_size;
data.Write(b, 0, f.Size);
}
byte[] result;
if (data.Length == 0)
{
if (br == null) {
result = File.ReadAllBytes(Bundle.path);
} else {
br.BaseStream.Seek(Bundle.offset, SeekOrigin.Begin);
result = br.ReadBytes(Bundle.head_size + Bundle.compressed_size + 12);
}
}
else
{
UncompressedSize = (int)data.Length + Bundle.uncompressed_size;
result = Bundle.AppendAndSave(data, br?.BaseStream ?? Bundle.Read());
}
FileToAdd.Clear();
data.Close();
return result;
}
See More Examples