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); }
/// <summary> /// Insert the filter into the filter chains. /// </summary> /// <param name="stream">Which stream's filter chains.</param> /// <param name="filter">What filter.</param> /// <param name="where">What position in the chains.</param> /// <param name="parameters">Additional parameters for the filter.</param> /// <returns>True if successful.</returns> public static bool AddToStream(PhpStream stream, string filter, FilterChainOptions where, object parameters) { PhpFilter readFilter, writeFilter; if ((stream.Options & StreamAccessOptions.Read) == 0) { where &= ~FilterChainOptions.Read; } if ((stream.Options & StreamAccessOptions.Write) == 0) { where &= ~FilterChainOptions.Write; } if ((where & FilterChainOptions.Read) > 0) { if (!GetFilter(filter, true, out readFilter, parameters)) { PhpException.Throw(PhpError.Warning, CoreResources.GetString("invalid_filter_name", filter)); return(false); } stream.AddFilter(readFilter, where); readFilter.OnCreate(); // Add to chain, (filters buffers too). } if ((where & FilterChainOptions.Write) > 0) { if (!GetFilter(filter, true, out writeFilter, parameters)) { PhpException.Throw(PhpError.Warning, CoreResources.GetString("invalid_filter_name", filter)); return(false); } stream.AddFilter(writeFilter, where); writeFilter.OnCreate(); // Add to chain. } return(true); }
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; }
/// <summary> /// filters (array) /// - array containing the names of any filters that have been stacked onto this stream. /// </summary> /// <param name="stream"></param> /// <returns></returns> private static PhpArray GetFiltersName(PhpStream/*!*/stream) { PhpArray array = new PhpArray(); foreach (PhpFilter f in stream.StreamFilters) array.Add(f.FilterName); return array; }
/// <summary> /// Creates a new <see cref="PhpIniParser"/> operating on a given input stream. /// </summary> /// <param name="stream">The input stream. Should be open in binary mode.</param> /// <param name="callbacks">Implementation of the parser callbacks invoked during parsing.</param> private PhpIniParser(PhpStream stream, IParserCallbacks callbacks) { this.lineGetter = new LineGetterStream(stream); this.callbacks = callbacks; }
public LineGetterStream(PhpStream stream) { if (stream == null) throw new ArgumentNullException("stream"); this.stream = stream; }
/// <summary> /// Parses an INI-style configuration file. /// </summary> /// <param name="stream">A stream referring to the file to parse. Should be open in binary mode.</param> /// <param name="callbacks">Implementation of the parser callbacks invoked during parsing.</param> /// <exception cref="ParseException">Parse error.</exception> /// <exception cref="ArgumentNullException"><paramref name="stream"/> or <paramref name="callbacks"/> is a <B>null</B> reference.</exception> /// <exception cref="ArgumentException">Stream is was not opened as binary.</exception> public static void Parse(PhpStream stream, IParserCallbacks callbacks) { if (stream == null) throw new ArgumentNullException("stream"); if (!stream.IsBinary) throw new ArgumentException("Stream must be binary"); if (callbacks == null) throw new ArgumentNullException("callbacks"); PhpIniParser parser = new PhpIniParser(stream, callbacks); parser.TopLevel(); }