pharo-users@lists.pharo.org

Any question about pharo is welcome

View all threads

Troubleshooting ByteArray

SR
sergio ruiz
Wed, Jan 17, 2024 3:33 PM

Hi, all.

I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example.

the Example looks like:

PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream.

When running this, I get the error:

Instance of ByteArray did not understand #isByteString

indeed, ByteArray does not have a method called isByteString.

I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF.

The method calling isByteString looks like:

ZnUTF8Encoder

next: count putAll: string startingAt: offset toStream: stream
"Write count characters from string starting at offset to stream."
"Overwritten for performance reasons - create a fast path for byte strings"

string isByteString
	ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ]
	ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ]

I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out.

Thanks!


peace,
sergio
photographer, journalist, visionary

Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2
#BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
@sergio_101@mastodon.social
https://sergio101.com
http://www.codeandmusic.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101

Hi, all. I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example. the Example looks like: PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream. When running this, I get the error: Instance of ByteArray did not understand #isByteString indeed, ByteArray does not have a method called isByteString. I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF. The method calling isByteString looks like: ZnUTF8Encoder next: count putAll: string startingAt: offset toStream: stream "Write count characters from string starting at offset to stream." "Overwritten for performance reasons - create a fast path for byte strings" string isByteString ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ] ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ] I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out. Thanks! ---- peace, sergio photographer, journalist, visionary Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2 #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV @sergio_101@mastodon.social https://sergio101.com http://www.codeandmusic.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
RO
Richard O'Keefe
Wed, Jan 17, 2024 11:43 PM

So the method is expecting some kind of string, but it received a
ByteArray, which is NOT any kind of string.
What's in the ByteArray?  Where did it come from?  Why isn't it a string?

On Thu, 18 Jan 2024 at 04:34, sergio ruiz sergio.rrd@gmail.com wrote:

Hi, all.

I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example.

the Example looks like:

PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream.

When running this, I get the error:

Instance of ByteArray did not understand #isByteString

indeed, ByteArray does not have a method called isByteString.

I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF.

The method calling isByteString looks like:

ZnUTF8Encoder

next: count putAll: string startingAt: offset toStream: stream
"Write count characters from string starting at offset to stream."
"Overwritten for performance reasons - create a fast path for byte strings"

string isByteString
ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ]
ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ]

I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out.

Thanks!


peace,
sergio
photographer, journalist, visionary

Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2
#BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
@sergio_101@mastodon.social
https://sergio101.com
http://www.codeandmusic.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101

So the method is expecting some kind of string, but it received a ByteArray, which is NOT any kind of string. What's in the ByteArray? Where did it come from? Why isn't it a string? On Thu, 18 Jan 2024 at 04:34, sergio ruiz <sergio.rrd@gmail.com> wrote: > > Hi, all. > > I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example. > > the Example looks like: > > PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream. > > > When running this, I get the error: > > Instance of ByteArray did not understand #isByteString > > indeed, ByteArray does not have a method called isByteString. > > I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF. > > The method calling isByteString looks like: > > > ZnUTF8Encoder > > next: count putAll: string startingAt: offset toStream: stream > "Write count characters from string starting at offset to stream." > "Overwritten for performance reasons - create a fast path for byte strings" > > string isByteString > ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ] > ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ] > > I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out. > > Thanks! > > ---- > peace, > sergio > photographer, journalist, visionary > > Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2 > #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV > @sergio_101@mastodon.social > https://sergio101.com > http://www.codeandmusic.com > http://www.twitter.com/sergio_101 > http://www.facebook.com/sergio101 >
TB
Todd Blanchard
Thu, Jan 18, 2024 12:13 AM

Try this:

(PDFDocument new compression: false)add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream.

Compression causes your string to be gzip’d which is a ByteArray and not a String of any kind.

Unfortunately, the write stream is a ZnCharacterWriteStream which is expecting some kind of String.

This is going to take some untangling so just turn off compression (which is on by default) and it seems to work.

On Jan 17, 2024, at 4:43 PM, Richard O'Keefe raoknz@gmail.com wrote:

So the method is expecting some kind of string, but it received a
ByteArray, which is NOT any kind of string.
What's in the ByteArray?  Where did it come from?  Why isn't it a string?

On Thu, 18 Jan 2024 at 04:34, sergio ruiz sergio.rrd@gmail.com wrote:

Hi, all.

I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example.

the Example looks like:

PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream.

When running this, I get the error:

Instance of ByteArray did not understand #isByteString

indeed, ByteArray does not have a method called isByteString.

I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF.

The method calling isByteString looks like:

ZnUTF8Encoder

next: count putAll: string startingAt: offset toStream: stream
"Write count characters from string starting at offset to stream."
"Overwritten for performance reasons - create a fast path for byte strings"

string isByteString
ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ]
ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ]

I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out.

Thanks!


peace,
sergio
photographer, journalist, visionary

Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2
#BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
@sergio_101@mastodon.social
https://sergio101.com
http://www.codeandmusic.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101

Try this: (PDFDocument new compression: false)add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream. Compression causes your string to be gzip’d which is a ByteArray and not a String of any kind. Unfortunately, the write stream is a ZnCharacterWriteStream which is expecting some kind of String. This is going to take some untangling so just turn off compression (which is on by default) and it seems to work. > On Jan 17, 2024, at 4:43 PM, Richard O'Keefe <raoknz@gmail.com> wrote: > > So the method is expecting some kind of string, but it received a > ByteArray, which is NOT any kind of string. > What's in the ByteArray? Where did it come from? Why isn't it a string? > > On Thu, 18 Jan 2024 at 04:34, sergio ruiz <sergio.rrd@gmail.com> wrote: >> >> Hi, all. >> >> I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example. >> >> the Example looks like: >> >> PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream. >> >> >> When running this, I get the error: >> >> Instance of ByteArray did not understand #isByteString >> >> indeed, ByteArray does not have a method called isByteString. >> >> I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF. >> >> The method calling isByteString looks like: >> >> >> ZnUTF8Encoder >> >> next: count putAll: string startingAt: offset toStream: stream >> "Write count characters from string starting at offset to stream." >> "Overwritten for performance reasons - create a fast path for byte strings" >> >> string isByteString >> ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ] >> ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ] >> >> I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out. >> >> Thanks! >> >> ---- >> peace, >> sergio >> photographer, journalist, visionary >> >> Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2 >> #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV >> @sergio_101@mastodon.social >> https://sergio101.com >> http://www.codeandmusic.com >> http://www.twitter.com/sergio_101 >> http://www.facebook.com/sergio101 >>
TB
Todd Blanchard
Thu, Jan 18, 2024 12:18 AM

I guess I’ll point you to the issue too.

PDFStreamPrinter>printPDFDataStream: aPDFDataStream
……
Line 13: (self compression) ifTrue: [ streamData := (self compressWithGZip: streamData) asByteArray  ].

On Jan 17, 2024, at 5:13 PM, Todd Blanchard via Pharo-users pharo-users@lists.pharo.org wrote:

Try this:

(PDFDocument new compression: false)add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream.

Compression causes your string to be gzip’d which is a ByteArray and not a String of any kind.

Unfortunately, the write stream is a ZnCharacterWriteStream which is expecting some kind of String.

This is going to take some untangling so just turn off compression (which is on by default) and it seems to work.

On Jan 17, 2024, at 4:43 PM, Richard O'Keefe raoknz@gmail.com wrote:

So the method is expecting some kind of string, but it received a
ByteArray, which is NOT any kind of string.
What's in the ByteArray?  Where did it come from?  Why isn't it a string?

On Thu, 18 Jan 2024 at 04:34, sergio ruiz sergio.rrd@gmail.com wrote:

Hi, all.

I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example.

the Example looks like:

PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream.

When running this, I get the error:

Instance of ByteArray did not understand #isByteString

indeed, ByteArray does not have a method called isByteString.

I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF.

The method calling isByteString looks like:

ZnUTF8Encoder

next: count putAll: string startingAt: offset toStream: stream
"Write count characters from string starting at offset to stream."
"Overwritten for performance reasons - create a fast path for byte strings"

string isByteString
ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ]
ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ]

I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out.

Thanks!


peace,
sergio
photographer, journalist, visionary

Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2
#BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
@sergio_101@mastodon.social
https://sergio101.com
http://www.codeandmusic.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101

I guess I’ll point you to the issue too. PDFStreamPrinter>printPDFDataStream: aPDFDataStream …… Line 13: (self compression) ifTrue: [ streamData := (self compressWithGZip: streamData) asByteArray ]. > On Jan 17, 2024, at 5:13 PM, Todd Blanchard via Pharo-users <pharo-users@lists.pharo.org> wrote: > > Try this: > > (PDFDocument new compression: false)add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream. > > Compression causes your string to be gzip’d which is a ByteArray and not a String of any kind. > > Unfortunately, the write stream is a ZnCharacterWriteStream which is expecting some kind of String. > > This is going to take some untangling so just turn off compression (which is on by default) and it seems to work. > >> On Jan 17, 2024, at 4:43 PM, Richard O'Keefe <raoknz@gmail.com> wrote: >> >> So the method is expecting some kind of string, but it received a >> ByteArray, which is NOT any kind of string. >> What's in the ByteArray? Where did it come from? Why isn't it a string? >> >> On Thu, 18 Jan 2024 at 04:34, sergio ruiz <sergio.rrd@gmail.com> wrote: >>> >>> Hi, all. >>> >>> I am working on creating a PDF with Artefact (https://github.com/pharo-contributions/Artefact) and am having an issue running the first example. >>> >>> the Example looks like: >>> >>> PDFDocument new add: (PDFPage new add: (PDFTextElement new text: 'Hello'; from: 10mm@10mm)); exportTo: 'test.pdf' asFileReference writeStream. >>> >>> >>> When running this, I get the error: >>> >>> Instance of ByteArray did not understand #isByteString >>> >>> indeed, ByteArray does not have a method called isByteString. >>> >>> I have tried creating a method that returns either true or false (I tried them both), but I have not successfully built the PDF. >>> >>> The method calling isByteString looks like: >>> >>> >>> ZnUTF8Encoder >>> >>> next: count putAll: string startingAt: offset toStream: stream >>> "Write count characters from string starting at offset to stream." >>> "Overwritten for performance reasons - create a fast path for byte strings" >>> >>> string isByteString >>> ifTrue: [ self next: count putAllByteString: string startingAt: offset toStream: stream ] >>> ifFalse: [ super next: count putAll: string startingAt: offset toStream: stream ] >>> >>> I TOTALLY get this. This is a whole bunch of very specific questions. But my ultimate goal is to take a deep dive into stream processing to figure this out. >>> >>> Thanks! >>> >>> ---- >>> peace, >>> sergio >>> photographer, journalist, visionary >>> >>> Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2 >>> #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV >>> @sergio_101@mastodon.social >>> https://sergio101.com >>> http://www.codeandmusic.com >>> http://www.twitter.com/sergio_101 >>> http://www.facebook.com/sergio101 >>>
SR
sergio ruiz
Thu, Jan 18, 2024 4:32 AM

Thanks for the input everyone!

I ended up just removing the compression.. In this case, this is not critical at all, so I can live with this..

Thanks, all!

On Jan 17, 2024, at 7:18 PM, Todd Blanchard via Pharo-users pharo-users@lists.pharo.org wrote:

I guess I’ll point you to the issue too.

PDFStreamPrinter>printPDFDataStream: aPDFDataStream
……
Line 13: (self compression) ifTrue: [ streamData := (self compressWithGZip: streamData) asByteArray  ].

Thanks for the input everyone! I ended up just removing the compression.. In this case, this is not critical at all, so I can live with this.. Thanks, all! > On Jan 17, 2024, at 7:18 PM, Todd Blanchard via Pharo-users <pharo-users@lists.pharo.org> wrote: > > I guess I’ll point you to the issue too. > > PDFStreamPrinter>printPDFDataStream: aPDFDataStream > …… > Line 13: (self compression) ifTrue: [ streamData := (self compressWithGZip: streamData) asByteArray ]. ---- peace, sergio photographer, journalist, visionary Public Key: https://pgp.key-server.io/pks/lookup?op=get&search=0x69B08F58923AB3A2 #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV @sergio_101@mastodon.social https://sergio101.com http://www.codeandmusic.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101