hightower2 has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
hightower2 has quit [Read error: Connection reset by peer]
hightower2 has joined #crystal-lang
hightower2 has quit [Read error: Connection reset by peer]
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 268 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
<FromGitter>
<djberg96> Does something like this already exist in core?
<FromGitter>
<naqvis> don't believe stdlib have one
<FromGitter>
<djberg96> ok, thanks
<FromGitter>
<djberg96> and if there's a nicer way to do what I'm doing there, I'm all ears
<FromGitter>
<naqvis> all good, few suggestions ⏎ ⏎ 1) you can follow stdlib api style for params i.e accept `file` as `Path | String`, accept `encoding` etc params ⏎ 2) you can use `open` with block so you don't have to deal with closing file while you are done with reading [https://gitter.im/crystal-lang/crystal?at=63820ef5f9491f62c9cf700a]
<FromGitter>
<Blacksmoke16> so yes, should work just like java
gordea has joined #crystal-lang
gordea has quit [Client Quit]
gordea has joined #crystal-lang
jmdaemon has joined #crystal-lang
ur5us has joined #crystal-lang
renich has joined #crystal-lang
ur5us has quit [Quit: Leaving]
<FromGitter>
<djberg96> What's the equivalent of `"\xBA\xB4\u0000\u0000".unpack('i').first` in Crystal?
<FromGitter>
<djberg96> I'm poking around the String class, but just not seeing it I guess
<FromGitter>
<djberg96> (use case: i'm reading magic numbers out of image files)
<FromGitter>
<Blacksmoke16> what kind of image?
<FromGitter>
<Blacksmoke16> but it would be something with IO, where you do something like `io.read_bytes(Int32)` or `io.read_bytes Int32, IO::ByteFormat::BigEndian` depending on the type/endianess you want to read
<FromGitter>
<djberg96> Yep, got something like that using the block above from @naqvis, byte slice like `Bytes[66, 77, 186, 180, 0, 0]`. First 2 bytes are "BM", now i just need to conver the last 4 to an number.
<FromGitter>
<Blacksmoke16> dont even really need that method, can just open the file and call methods on the io and call it a day
<FromGitter>
<djberg96> well, i'm trying to use that method as a general solution, because I'm also reading magic values for other formats, like jpg, png, etc
<FromGitter>
<djberg96> so, just for the sake of argument, how would I convert a byte slice like `Bytes[186,180,0,0]` to an int?
<FromGitter>
<Blacksmoke16> first way that comes to mind is like `IO::Memory.new(bytes, writeable: false).read_bytes Int32`