develooper Front page | perl.perl6.users | Postings from February 2019

Re: Fastest way to convert from a Buf to a Str?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
February 4, 2019 02:49
Subject:
Re: Fastest way to convert from a Buf to a Str?
Message ID:
9ad39982-2dd3-7f56-27f5-ba184fe160cf@zoho.com
On 2/3/19 5:26 PM, Darren Duncan wrote:
> On 2019-02-02 7:22 PM, ToddAndMargo via perl6-users wrote:
>> I need to read a file into a buffer (NO CONVERSIONS!)
>> and then convert it to a string (again with no
>> conversions).
> 
> I think you're making an impossible request.  

Don't forget that I think everywhere on this list is
a bloody genius.

> If preserving exact bytes 
> is important, then you want to keep your data in a type that represents 
> a sequence of bytes, such as Blob of Buf.  A Str represents a sequence 
> of characters, which are NOT bytes, so if you're wanting to have a Str 
> that is saying you don't care about the bytes.  Given what you keep 
> saying, I'd say skip the Str and just use Buf or Blob etc full stop. -- 
> Darren Duncan



Hi Darren,

for ( @$BinaryFile ) -> $Char { $StrFile ~= chr($Char); }

Does the trick, but it takes up to 15 seconds.  Way
too slow.

I have another post looking to see if any of the other
decodes will work.  So maybe...

My big issue is that the data I am looking through uses four
nuls in a row as a delimiter.  If these get dropped, I
won't be able to find anything.

Your idea about just skipping Str is along the line I have
also been thinking.  Brad has been helping me with "index" for
a Buf.  I haven't had a shot at trying his corrections to my
code yet.

-T

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About