public static HassiumObject readallbytes(VirtualMachine vm, HassiumObject self, SourceLocation location, params HassiumObject[] args) { var file = (self as HassiumFile); if (!File.Exists(file.AbsolutePath.String)) { vm.RaiseException(HassiumFileNotFoundException.FileNotFoundExceptionTypeDef._new(vm, null, location, file.AbsolutePath)); return(Null); } if (file.closed) { vm.RaiseException(HassiumFileClosedException.FileClosedExceptionTypeDef._new(vm, null, location, self, get_abspath(vm, self, location))); return(Null); } HassiumByteArray list = new HassiumByteArray(new byte[0], new HassiumObject[0]); file.Reader.BaseStream.Position = 0; while (file.Reader.BaseStream.Position < file.Reader.BaseStream.Length) { list.Values.Add(file.Reader.ReadBytes(1)[0]); } return(list); }
public HassiumObject readbytes(VirtualMachine vm, HassiumObject self, SourceLocation location, params HassiumObject[] args) { var socket = (self as HassiumSocket); if (socket.Closed) { vm.RaiseException(HassiumSocketClosedException.SocketClosedExceptionTypeDef._new(vm, null, location, this)); return(Null); } HassiumByteArray list = new HassiumByteArray(new byte[0], new HassiumObject[0]); int count = (int)args[0].ToInt(vm, args[0], location).Int; for (int i = 0; i < count; i++) { HassiumList.add(vm, list, location, new HassiumChar((char)socket.Reader.ReadBytes(1)[0])); } return(list); }
public HassiumByteArray readbytes(VirtualMachine vm, HassiumObject self, SourceLocation location, params HassiumObject[] args) { HassiumByteArray list = new HassiumByteArray(new byte[0], new HassiumObject[0]); var stream = new FileStream(args[0].ToString(vm, args[0], location).String, FileMode.Open, FileAccess.Read, FileShare.Read); var reader = new BinaryReader(stream); try { while (reader.BaseStream.Position < reader.BaseStream.Length) { list.Values.Add(reader.ReadBytes(1)[0]); } return(list); } finally { reader.Close(); } }