Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Heisenberg may have slept here...


devel / comp.lang.mumps / Re: YottaDB: writing a binary file

SubjectAuthor
* YottaDB: writing a binary fileed de moel
`* Re: YottaDB: writing a binary fileK.S. Bhaskar
 +- Re: YottaDB: writing a binary fileK.S. Bhaskar
 `* Re: YottaDB: writing a binary fileed de moel
  `* Re: YottaDB: writing a binary fileK.S. Bhaskar
   `* Re: YottaDB: writing a binary fileed de moel
    `* Re: YottaDB: writing a binary fileSam Habiel
     `- Re: YottaDB: writing a binary fileed de moel

1
YottaDB: writing a binary file

<eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=507&group=comp.lang.mumps#507

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ac8:6b41:0:b0:3ae:d88a:7d1d with SMTP id x1-20020ac86b41000000b003aed88a7d1dmr910581qts.538.1674576567618;
Tue, 24 Jan 2023 08:09:27 -0800 (PST)
X-Received: by 2002:a05:6871:b1a0:b0:15f:7e1:a517 with SMTP id
an32-20020a056871b1a000b0015f07e1a517mr1897724oac.13.1674576567176; Tue, 24
Jan 2023 08:09:27 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Tue, 24 Jan 2023 08:09:26 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=71.174.62.16; posting-account=j7lJmQoAAADTx0Apfk15DZ7D0qlYy4zv
NNTP-Posting-Host: 71.174.62.16
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>
Subject: YottaDB: writing a binary file
From: eddemoel@gmail.com (ed de moel)
Injection-Date: Tue, 24 Jan 2023 16:09:27 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1359
 by: ed de moel - Tue, 24 Jan 2023 16:09 UTC

I'm trying to write a binary file.
I'm end up with a file that contains the UTF-8 escapes for the bytes with a value between 128 and 255.
To demonstrate: I tried this:
Set file="x.tmp"
Open file:(newversion:stream:nowrap:nodelimiter:chset="M")
Use file For i=0:1:255 Write $Char(i)
c file
the file that gets created has 385 bytes, while I would expect 256.

Any suggestions?

Re: YottaDB: writing a binary file

<c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=508&group=comp.lang.mumps#508

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ac8:4457:0:b0:3b5:5e27:1f0f with SMTP id m23-20020ac84457000000b003b55e271f0fmr1362720qtn.462.1674648104118;
Wed, 25 Jan 2023 04:01:44 -0800 (PST)
X-Received: by 2002:aca:2812:0:b0:35b:7d0f:fa9a with SMTP id
18-20020aca2812000000b0035b7d0ffa9amr2037110oix.29.1674648103688; Wed, 25 Jan
2023 04:01:43 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Wed, 25 Jan 2023 04:01:43 -0800 (PST)
In-Reply-To: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=108.36.235.25; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 108.36.235.25
References: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com>
Subject: Re: YottaDB: writing a binary file
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Wed, 25 Jan 2023 12:01:44 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 18
 by: K.S. Bhaskar - Wed, 25 Jan 2023 12:01 UTC

On Tuesday, January 24, 2023 at 11:09:28 AM UTC-5, ed de moel wrote:
> I'm trying to write a binary file.
> I'm end up with a file that contains the UTF-8 escapes for the bytes with a value between 128 and 255.
> To demonstrate: I tried this:
> Set file="x.tmp"
> Open file:(newversion:stream:nowrap:nodelimiter:chset="M")
> Use file For i=0:1:255 Write $Char(i)
> c file
> the file that gets created has 385 bytes, while I would expect 256.
>
> Any suggestions?

Ed, try $ZCHAR() (https://docs.yottadb.com/ProgrammersGuide/functions.html#zchar) which refers to bytes. $CHAR() (https://docs.yottadb.com/ProgrammersGuide/functions.html#char) refers to characters.

Regards
– Bhaskar

Re: YottaDB: writing a binary file

<b12a023a-b1aa-468d-b87d-510c4a75735fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=509&group=comp.lang.mumps#509

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a05:6214:4256:b0:535:663f:f400 with SMTP id ne22-20020a056214425600b00535663ff400mr826577qvb.40.1674648196088;
Wed, 25 Jan 2023 04:03:16 -0800 (PST)
X-Received: by 2002:a05:6871:4183:b0:15f:9e8:542a with SMTP id
lc3-20020a056871418300b0015f09e8542amr2464339oab.267.1674648195687; Wed, 25
Jan 2023 04:03:15 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Wed, 25 Jan 2023 04:03:15 -0800 (PST)
In-Reply-To: <c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=108.36.235.25; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 108.36.235.25
References: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com> <c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b12a023a-b1aa-468d-b87d-510c4a75735fn@googlegroups.com>
Subject: Re: YottaDB: writing a binary file
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Wed, 25 Jan 2023 12:03:16 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2245
 by: K.S. Bhaskar - Wed, 25 Jan 2023 12:03 UTC

On Wednesday, January 25, 2023 at 7:01:45 AM UTC-5, K.S. Bhaskar wrote:
> On Tuesday, January 24, 2023 at 11:09:28 AM UTC-5, ed de moel wrote:
> > I'm trying to write a binary file.
> > I'm end up with a file that contains the UTF-8 escapes for the bytes with a value between 128 and 255.
> > To demonstrate: I tried this:
> > Set file="x.tmp"
> > Open file:(newversion:stream:nowrap:nodelimiter:chset="M")
> > Use file For i=0:1:255 Write $Char(i)
> > c file
> > the file that gets created has 385 bytes, while I would expect 256.
> >
> > Any suggestions?
> Ed, try $ZCHAR() (https://docs.yottadb.com/ProgrammersGuide/functions.html#zchar) which refers to bytes. $CHAR() (https://docs.yottadb.com/ProgrammersGuide/functions.html#char) refers to characters.
>
> Regards
> – Bhaskar

Also, remember to set $X to zero before closing the file. Otherwise, you may get a line terminator added at the end.

Regards
– Bhaskar

Re: YottaDB: writing a binary file

<5f9f12e5-4762-4e41-a47d-39e1646c7255n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=510&group=comp.lang.mumps#510

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ae9:f212:0:b0:706:6f2b:f37a with SMTP id m18-20020ae9f212000000b007066f2bf37amr1094780qkg.518.1674659689174;
Wed, 25 Jan 2023 07:14:49 -0800 (PST)
X-Received: by 2002:a05:6870:1b14:b0:14f:e693:ba8c with SMTP id
hl20-20020a0568701b1400b0014fe693ba8cmr2679885oab.142.1674659688916; Wed, 25
Jan 2023 07:14:48 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Wed, 25 Jan 2023 07:14:48 -0800 (PST)
In-Reply-To: <c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.174.62.16; posting-account=j7lJmQoAAADTx0Apfk15DZ7D0qlYy4zv
NNTP-Posting-Host: 71.174.62.16
References: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com> <c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5f9f12e5-4762-4e41-a47d-39e1646c7255n@googlegroups.com>
Subject: Re: YottaDB: writing a binary file
From: eddemoel@gmail.com (ed de moel)
Injection-Date: Wed, 25 Jan 2023 15:14:49 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1311
 by: ed de moel - Wed, 25 Jan 2023 15:14 UTC

That works, but it means that instead of
Write blob
I have to
For ii=1:1:$Length(blob) Write $Zchar($Ascii(blob,ii))

Re: YottaDB: writing a binary file

<a890c6a0-ca47-4897-8022-0f8b989fabafn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=511&group=comp.lang.mumps#511

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a05:622a:5c88:b0:3b4:2946:c083 with SMTP id ge8-20020a05622a5c8800b003b42946c083mr737365qtb.457.1674662387553;
Wed, 25 Jan 2023 07:59:47 -0800 (PST)
X-Received: by 2002:a05:6870:be97:b0:15e:d540:a55b with SMTP id
nx23-20020a056870be9700b0015ed540a55bmr2820696oab.29.1674662387217; Wed, 25
Jan 2023 07:59:47 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Wed, 25 Jan 2023 07:59:46 -0800 (PST)
In-Reply-To: <5f9f12e5-4762-4e41-a47d-39e1646c7255n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=108.36.235.25; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 108.36.235.25
References: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>
<c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com> <5f9f12e5-4762-4e41-a47d-39e1646c7255n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a890c6a0-ca47-4897-8022-0f8b989fabafn@googlegroups.com>
Subject: Re: YottaDB: writing a binary file
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Wed, 25 Jan 2023 15:59:47 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1924
 by: K.S. Bhaskar - Wed, 25 Jan 2023 15:59 UTC

On Wednesday, January 25, 2023 at 10:14:50 AM UTC-5, ed de moel wrote:
> That works, but it means that instead of
> Write blob
> I have to
> For ii=1:1:$Length(blob) Write $Zchar($Ascii(blob,ii))

Ed, I'm not sure exactly what you are trying to do, but hope this helps:

YDB>for i=1:1:256 s $zextract(x,i)=$zchar(i-1)

YDB>write $zlength(x)
256
YDB>set f="/tmp/tmp.tmp" open f:(newversion:chset="m")

YDB>use f write x set $x=0 close f

YDB>zsystem "ls -l /tmp/tmp.tmp"
-rw-r--r-- 1 bhaskar gtc 256 Jan 25 10:58 /tmp/tmp.tmp

YDB>write $zchset
UTF-8
YDB>

Regards
– Bhaskar

Re: YottaDB: writing a binary file

<1a57a2ee-a494-435b-b817-ac2ba40aa46an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=512&group=comp.lang.mumps#512

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a05:6214:5cc8:b0:50c:bbc4:12f7 with SMTP id lk8-20020a0562145cc800b0050cbbc412f7mr1221044qvb.87.1674663030373;
Wed, 25 Jan 2023 08:10:30 -0800 (PST)
X-Received: by 2002:aca:ea07:0:b0:365:bc33:a74a with SMTP id
i7-20020acaea07000000b00365bc33a74amr1987538oih.68.1674663030106; Wed, 25 Jan
2023 08:10:30 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Wed, 25 Jan 2023 08:10:29 -0800 (PST)
In-Reply-To: <a890c6a0-ca47-4897-8022-0f8b989fabafn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.174.62.16; posting-account=j7lJmQoAAADTx0Apfk15DZ7D0qlYy4zv
NNTP-Posting-Host: 71.174.62.16
References: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>
<c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com> <5f9f12e5-4762-4e41-a47d-39e1646c7255n@googlegroups.com>
<a890c6a0-ca47-4897-8022-0f8b989fabafn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1a57a2ee-a494-435b-b817-ac2ba40aa46an@googlegroups.com>
Subject: Re: YottaDB: writing a binary file
From: eddemoel@gmail.com (ed de moel)
Injection-Date: Wed, 25 Jan 2023 16:10:30 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1388
 by: ed de moel - Wed, 25 Jan 2023 16:10 UTC

I'm building a jpg (image) file from a web-upload.
I'll try your suggestion.

Thanks,
Ed

Re: YottaDB: writing a binary file

<b732c83b-dcf9-4dde-9ac7-f84e69192859n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=513&group=comp.lang.mumps#513

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a0c:f883:0:b0:537:7c92:6f82 with SMTP id u3-20020a0cf883000000b005377c926f82mr169999qvn.81.1674739593324;
Thu, 26 Jan 2023 05:26:33 -0800 (PST)
X-Received: by 2002:a05:6870:1b14:b0:14f:e693:ba8c with SMTP id
hl20-20020a0568701b1400b0014fe693ba8cmr3024678oab.142.1674739592940; Thu, 26
Jan 2023 05:26:32 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Thu, 26 Jan 2023 05:26:32 -0800 (PST)
In-Reply-To: <1a57a2ee-a494-435b-b817-ac2ba40aa46an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.162.243.192; posting-account=1RT8nQoAAAAj9lvLkm8f9L-U6g6gYLit
NNTP-Posting-Host: 71.162.243.192
References: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>
<c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com> <5f9f12e5-4762-4e41-a47d-39e1646c7255n@googlegroups.com>
<a890c6a0-ca47-4897-8022-0f8b989fabafn@googlegroups.com> <1a57a2ee-a494-435b-b817-ac2ba40aa46an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b732c83b-dcf9-4dde-9ac7-f84e69192859n@googlegroups.com>
Subject: Re: YottaDB: writing a binary file
From: sam.habiel@gmail.com (Sam Habiel)
Injection-Date: Thu, 26 Jan 2023 13:26:33 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2334
 by: Sam Habiel - Thu, 26 Jan 2023 13:26 UTC

On Wednesday, January 25, 2023 at 11:10:31 AM UTC-5, ed de moel wrote:
> I'm building a jpg (image) file from a web-upload.
> I'll try your suggestion.
>
> Thanks,
> Ed
Ed,

Unfortunately, reading and writing a binary file is pretty difficult.

I have code that is working and is in production:

https://gitlab.com/YottaDB/Util/YDB-Web-Server/-/blob/master/src/_ydbwebapi.m#L118

Read is:

1. Open with "FIXED": O PATH:(REWIND:READONLY:FIXED:CHSET="M")
2. Read length-limited reads: N X F R X#4079:0 S HTTPRSP(C)=X,C=C+1 Q:$ZEOF
3. Close file.

https://gitlab.com/YottaDB/Util/YDB-Web-Server/-/blob/master/src/_ydbwebrsp.m#L239

Write is:

1. Open with STREAM, NOWRAP and CHSET of M: o file:(newversion:stream:nowrap:chset="M")
2. Write Data
3. Set $X to zero
4. Close file.

Keep in mind that if you are operating in UTF-8 mode (the default), you always need to use the byte operators $ZCHAR, $ZASCII, and $ZLENGTH and $ZPIECE.

--Sam

Re: YottaDB: writing a binary file

<dad874c9-78bc-4c95-a73a-dedafc1afd11n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=514&group=comp.lang.mumps#514

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ac8:698b:0:b0:3b6:3d93:585e with SMTP id o11-20020ac8698b000000b003b63d93585emr1363036qtq.75.1674753942825;
Thu, 26 Jan 2023 09:25:42 -0800 (PST)
X-Received: by 2002:a9d:6b03:0:b0:66e:86d3:c856 with SMTP id
g3-20020a9d6b03000000b0066e86d3c856mr1929823otp.121.1674753942584; Thu, 26
Jan 2023 09:25:42 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Thu, 26 Jan 2023 09:25:42 -0800 (PST)
In-Reply-To: <b732c83b-dcf9-4dde-9ac7-f84e69192859n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.174.62.16; posting-account=j7lJmQoAAADTx0Apfk15DZ7D0qlYy4zv
NNTP-Posting-Host: 71.174.62.16
References: <eb7edf51-03e6-4ff0-8246-85c4e0321639n@googlegroups.com>
<c5e99bb9-82a1-44b3-b6b0-eedab6750b26n@googlegroups.com> <5f9f12e5-4762-4e41-a47d-39e1646c7255n@googlegroups.com>
<a890c6a0-ca47-4897-8022-0f8b989fabafn@googlegroups.com> <1a57a2ee-a494-435b-b817-ac2ba40aa46an@googlegroups.com>
<b732c83b-dcf9-4dde-9ac7-f84e69192859n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dad874c9-78bc-4c95-a73a-dedafc1afd11n@googlegroups.com>
Subject: Re: YottaDB: writing a binary file
From: eddemoel@gmail.com (ed de moel)
Injection-Date: Thu, 26 Jan 2023 17:25:42 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1933
 by: ed de moel - Thu, 26 Jan 2023 17:25 UTC

It's tricky indeed.
In my case, this is what ended up working best:

-- code that builds the binary blob (this code works for both YottaDB and Iris, so, no $ZChar in there) --
Open file:(newversion:stream:nowrap:nodelimiter:chset="M") Use file
For ii=1:1:$Length(blob) Write *$Ascii(blob,ii)
Set $X=0
Close file

(And I'm sure I could have used $ZChar($Ascii(blob,ii)) instead of *$Ascii(blob,ii),
but with *$Ascii(blob,ii) the code remains just a tad closer to the standard.)

Thanks for all the help,
Ed

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor