public static object load(CodeContext /*!*/ context, PythonIOModule._IOBase /*!*/ file) { if (file == null) { throw PythonOps.TypeError("expected file, found None"); } return(MarshalOps.GetObject(FileEnumerator(context, file))); }
public static void dump(CodeContext /*!*/ context, object value, PythonIOModule._IOBase /*!*/ file, int version = PythonMarshal.version) { if (file == null) { throw PythonOps.TypeError("expected file, found None"); } file.write(context, dumps(value, version)); }
private static IEnumerator <byte> FileEnumerator(CodeContext /*!*/ context, PythonIOModule._IOBase /*!*/ file) { object bytes = file.read(context, 0); if (!(bytes is Bytes)) { throw PythonOps.TypeError($"file.read() returned not bytes but {Runtime.Types.DynamicHelpers.GetPythonType(bytes).Name}"); } for (; ;) { Bytes data = (Bytes)file.read(context, 1); if (data.Count == 0) { yield break; } yield return((byte)data[0]); } }