private static void ReadAllBytes(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); string path = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null; byte[] buffer = null; Exception exception = null; if (FILE.Exists(path)) { try { buffer = FILE.ReadAllBytes(path); } catch (Exception e) { exception = e; } } if (buffer != null) { arguments.SetReturnValue(buffer); } else if (exception == null) { Throwable.FileNotFoundException(arguments.VirtualMachine); } else { Throwable.Exception(arguments.VirtualMachine, exception); } }
private static void CallGetFileInfo(IntPtr info, Action <NSJSFunctionCallbackInfo, string> callback) { if (callback == null) { throw new ArgumentNullException("callback"); } NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); string path = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null; if (!FILE.Exists(path)) { Throwable.FileNotFoundException(arguments.VirtualMachine); } else { callback(arguments, path); } }
private static void ReadAllText(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); string path = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null; string contents = null; Exception exception = null; if (FILE.Exists(path)) { Encoding encodings = NSJSEncoding.DefaultEncoding; if (arguments.Length > 1) { encodings = NSJSEncoding.GetEncoding(arguments[1] as NSJSObject); } try { contents = FILE.ReadAllText(path, encodings); } catch (Exception e) { exception = e; } } if (contents != null) { arguments.SetReturnValue(contents); } else if (exception == null) { Throwable.FileNotFoundException(arguments.VirtualMachine); } else { Throwable.Exception(arguments.VirtualMachine, exception); } }