<[0x1eef]>
That's what I found weird. It can emit JSON that it can't parse again.
<gr33n7007h>
the only thing i can reason is it's ruby specific: parse returns the option; "{\"max_nesting\":false,\"allow_nan\":true,\"script_safe\":false}"
<[0x1eef]>
Indeed. This works: JSON.parse(JSON.dump(x: 0.0/0.0), allow_nan: true) - but's weird, especially for a default.
<gr33n7007h>
there must be some reasoning for it, those ruby folks aren't all crazy ;)
<gr33n7007h>
[0x1eef]: hang on, what's weird?
<gr33n7007h>
NaN and Inf is not valid json.
<[0x1eef]>
By default JSON.dump(x: 0.0/.0.0) will emit NaN, and then JSON.parse won't be able to parse it again (unless you set allow_nan: true). SO the default half works.
<gr33n7007h>
leah2: yeah, don't use load, its unsafe
<[0x1eef]>
I guess not.
<gr33n7007h>
load_default_options allow NaN too
<gr33n7007h>
leah2: load calls parse after setting a few options and stuff
<leah2>
unsafe json loading, statements dreamed up by the utterly deranged
xdminsy has quit [Read error: Connection reset by peer]
<gr33n7007h>
well, from untrusted input. basically dump/load allows NaN in its default options, parse otoh doesn't
<leah2>
doesnt seem very unsafe :p
<gr33n7007h>
did read about all the quirks about this years ago, god knows what article it was
<gr33n7007h>
leah2: :P
<leah2>
i know yaml is unsafe
<leah2>
and marshal ofc
<gr33n7007h>
lol yeah, well unsafe XD
poems has quit [Ping timeout: 246 seconds]
poems has joined #ruby
bovis has joined #ruby
<bovis>
https://bpa.st/5EYQ I'm trying to copy an existing zip file into memory, edit the copy, and then open the resulting edited stream. Why do I get the error "End-of-central-directory signature not found" when I open the resulting new zip file?
pascal_blaze has joined #ruby
[0x1eef] has quit [Quit: Leaving]
[0x1eef] has joined #ruby
pascal_blaze has quit [Client Quit]
ken_barber has quit [Quit: Client closed]
<adam12>
bovis: What zip library is this?
desnudopenguino has quit [Ping timeout: 255 seconds]
desnudopenguino has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
desnudopenguino has quit [Ping timeout: 252 seconds]
desnudopenguino has joined #ruby
karolis has quit [Ping timeout: 260 seconds]
gr33n7007h has quit [Ping timeout: 252 seconds]
konsolebox has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
_ht has quit [Remote host closed the connection]
<bovis>
adam12: rubyzip. I require 'zip' at the top of the document.
<adam12>
bovis: You don't show how you're writing the buffer out.
<adam12>
bovis: Is it any different if you call `flush` first? `zip_data.flush`
sagax has quit [Ping timeout: 255 seconds]
user71 has quit [Quit: Leaving]
<bovis>
adam12: Rubyzip version is 2.3.2. zip_data.flush doesn't help.
<adam12>
bovis: I see it calls flush automatically from the code.
<adam12>
bovis: tbh, probably too many things going on here. I'd try making a minimal example without rails & send_file (and without that ensure close block).
<adam12>
If the zip is fine with those eliminated, see if you can write to a Tempfile then send_file the tempfile.
<bovis>
A separate but similar instance with the rails, this works fine https://bpa.st/OY6Q
<bovis>
The only difference being that, in the latter, I'm not editing the existing zip in place. The tempfile is blank.
pascal_blaze has joined #ruby
<weaksauce>
why not close the zip_data above send_data
<bovis>
weaksauce: Just tried it. No change in results.
<bovis>
Is it necessary to close the Zip::OutputStream within the block I've opened? It feels like something should go after the shovel: new_zip << File.read(...)
<weaksauce>
probably yeah
<weaksauce>
close
<weaksauce>
Closes the stream and writes the central directory to the zip file
<weaksauce>
same with close_buffer
karolis has joined #ruby
CrazyEddy has quit [Quit: Reconnecting]
<adam12>
bovis: How about `send_data(zip_data.string, ... rest of stuff)` - specifically, `zip_data.string`
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
desnudopenguino has quit [Ping timeout: 268 seconds]
<havenwood>
bovis: Is the latter the output you're shooting for?
<havenwood>
bovis: Just an aside from your other gist, but Tempfile.create is preferred to Tempfile.new. Also, if you pass `"tmp.zip"` it till use use it as a prefix like `tmp.zipxoxo`. To have the latter be the extension, pass an Array like `%w[tmp .zip]` for `tmpxoxo.zip`.
<havenwood>
And a block is preferred, to close the Tempfile.
<havenwood>
The docs expound on why Tempfile.create is more than a stylistic difference from Tempfile.new.
<[0x1eef]>
FWIW :) Most of the time I use Tempfile in a way similar to this: Tempfile.new("namespace").tap { [File.chmod(0, _1.path), File.unlink(_1.path)] }.
<jas-maelstrom>
Is there a way to programmatically draw/create a .TIFF image in Ruby? This would be for a small utility for work in a Windows environment.
<weaksauce>
jas-maelstrom what are you trying to make?
<jas-maelstrom>
I want to be able to generate TIFF images, actually, sorry, multi-page TIFF images and be able to programmatically write certain info from a database on them.
<jas-maelstrom>
I'm in QA and our application is built around TIFF images so TIFF is a requirement here, multiple-page TIFF.
<jas-maelstrom>
I just need to generate image files customized with specific data and ideally, generate them of certain file sizes.