/// <summary> /// Read uncompressed file contents into the specified buffer. Returns /// 0 if at the end of file, or the number of bytes read. /// Throws an exception if an error occurred. /// </summary> public int ReadFile(byte[] buffer) { if (buffer == null || buffer.Length == 0) { throw new ArgumentException("Buffer can't be null or zero length.", "buffer"); } var pb = new PinnedObject(buffer); var retval = CfxApi.ZipReader.cfx_zip_reader_read_file(NativePtr, pb.PinnedPtr, (UIntPtr)buffer.LongLength); pb.Free(); if (retval < 0) { throw new CfxException("Failed to read from zip file"); } return(retval); }
/// <summary> /// Read up to (buffer.Length - bufferOffset) bytes into |buffer|. Reading begins at /// the specified byte dataOffset. Writing begins at the /// specified byte bufferOffset. /// Returns the number of bytes read. /// </summary> public int GetData(byte[] buffer, int bufferOffset, int dataOffset) { if (buffer == null || buffer.Length == 0) { throw new ArgumentException("Buffer is null or zero length.", "buffer"); } var maxBytes = buffer.Length - bufferOffset; if (maxBytes <= 0) { throw new ArgumentException("bufferOffset >= buffer.Length.", "bufferOffset"); } var po = new PinnedObject(buffer); var retval = CfxApi.BinaryValue.cfx_binary_value_get_data(NativePtr, po.PinnedPtr + bufferOffset, (UIntPtr)maxBytes, (UIntPtr)dataOffset); po.Free(); return((int)retval); }
/// <summary> /// Retrieve the page ranges. /// </summary> /// <remarks> /// See also the original CEF documentation in /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_print_settings_capi.h">cef/include/capi/cef_print_settings_capi.h</see>. /// </remarks> public CfxRange[] GetPageRanges() { var rangesCount = CfxApi.PrintSettings.cfx_print_settings_get_page_ranges_count(NativePtr); IntPtr[] pp = new IntPtr[(ulong)rangesCount]; PinnedObject pp_pinned = new PinnedObject(pp); int ranges_nomem; CfxApi.PrintSettings.cfx_print_settings_get_page_ranges(NativePtr, ref rangesCount, pp_pinned.PinnedPtr, out ranges_nomem); pp_pinned.Free(); if (ranges_nomem != 0) { throw new OutOfMemoryException(); } var retval = new CfxRange[(ulong)rangesCount]; for (ulong i = 0; i < (ulong)rangesCount; ++i) { retval[i] = CfxRange.WrapOwned(pp[i]); } return(retval); }
public PinnedString(string s) { Obj = new PinnedObject(s); Length = s != null ? s.Length : 0; }