caxlsx: Package#to_stream does not work in 3.2.0

Hello 👋

I’ve noticed that since the update to v3.2.0, Package#to_stream method stopped working. I suspect the issue is due to this change:

v3.2.0

package = Axlsx::Package.new
package.to_stream.external_encoding
=> #<Encoding:ASCII-8BIT>

While in the previous version, the encoding was UTF-8:

package = Axlsx::Package.new
package.to_stream.external_encoding
=> #<Encoding:UTF-8>

When I try to write the stream to the file (as per the docs) I get the following error:

Encoding::UndefinedConversionError: "\xEC" from ASCII-8BIT to UTF-8

Since this issue was a breaking change for me, I believe it should’ve been stated as such in the Changelog.md

Btw I’ve switched to using Package#serialize in the meantime and it is working. 🙂

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 19 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I added a commit that makes sure all examples use binary mode when writing the stream to a file. I think this should be enough – in the end, this is not about caxlsx but about how to use File.write.

Forcing UTF-8 worked for me. @package.to_stream.read.force_encoding('UTF-8')