public FileHandleDataSource(PhpStream handle, int flength) { this.handle = handle; this.flength = flength; //TODO : Replace memorystream with a better reading/seeking class PhpBytes data; if (flength > 0) { data = handle.ReadBytes(flength); } else { data = handle.ReadBinaryContents(-1); } this.m_ms = new MemoryStream(data.ReadonlyData); }
public static bool BeginIO(Stream stream, PhpStream phpStream, StreamAccessOptions access, int desc_no) { if (access == StreamAccessOptions.Read && !phpStream.CanWrite || access == StreamAccessOptions.Write && !phpStream.CanRead) { PhpException.Throw(PhpError.Warning, LibResources.GetString("descriptor_item_invalid_mode", desc_no)); return false; } ActivePipe pipe = new ActivePipe(); pipe.stream = stream; pipe.phpStream = phpStream; pipe.access = access; pipe.callback = new AsyncCallback(pipe.Callback); if (access == StreamAccessOptions.Read) { var buffer = new byte[BufferSize]; stream.BeginRead(buffer, 0, buffer.Length, pipe.callback, null); pipe.buffer = new PhpBytes(buffer); } else { pipe.buffer = phpStream.ReadBytes(BufferSize); if (pipe.buffer != null) stream.BeginWrite(pipe.buffer.ReadonlyData, 0, pipe.buffer.Length, pipe.callback, null); else stream.Close(); } return true; }