digitalmars.D.learn - Write binary data as a file
- Alexander Zhirov (22/22) Aug 02 2022 I'm trying to write a mechanism for writing and reading from
- H. S. Teoh (9/15) Aug 02 2022 Don't use `write` for binary data. Use instead File.rawWrite:
- Adam D Ruppe (3/4) Aug 02 2022 my database layer is doing to!string(that_ubyte) which is wrong.
- Alexander Zhirov (3/8) Aug 02 2022 It's decided! After the fix, everything works! Thank you very
I'm trying to write a mechanism for writing and reading from Postgres. Using the Adama D. Ruppe library. I write data to Postgres in the form of this code: ```d ubyte[] bytes = cast(ubyte[])read("myFile"); PostgresResult resultQuery = cast(PostgresResult) db.query("insert into amts.t_client_xrdp_settings (pid_client, settings_file) values (?, ?)", id, bytes); assert(resultQuery !is null); ``` Data appears in the database. Now I'm trying to do the reverse process. Get data from Postgres and create a file: ```d auto result = db.query("select tcxs.settings_file as dbfile from amts.t_client_xrdp_settings tcxs where tcxs.pid_client = ?", id); ubyte[] bytes = cast(ubyte[])result.front()["dbfile"]; write("newFile", bytes); ``` As a result, I get only a set of text data. I am sure that my mechanism lacks refinement. It remains only to find out which one.
Aug 02 2022
On Tue, Aug 02, 2022 at 11:10:27AM +0000, Alexander Zhirov via Digitalmars-d-learn wrote: [...]```d auto result = db.query("select tcxs.settings_file as dbfile from amts.t_client_xrdp_settings tcxs where tcxs.pid_client = ?", id); ubyte[] bytes = cast(ubyte[])result.front()["dbfile"]; write("newFile", bytes); ```Don't use `write` for binary data. Use instead File.rawWrite: ubyte[] data = ...; File f = File("dbfile", "w"); f.rawWrite(data[]); T -- This is a tpyo.
Aug 02 2022
On Tuesday, 2 August 2022 at 11:10:27 UTC, Alexander Zhirov wrote:As a result, I get only a set of text data.my database layer is doing to!string(that_ubyte) which is wrong. gonna see about pushing a fix
Aug 02 2022
On Tuesday, 2 August 2022 at 15:30:13 UTC, Adam D Ruppe wrote:On Tuesday, 2 August 2022 at 11:10:27 UTC, Alexander Zhirov wrote:It's decided! After the fix, everything works! Thank you very much!As a result, I get only a set of text data.my database layer is doing to!string(that_ubyte) which is wrong. gonna see about pushing a fix
Aug 02 2022