ademenev

ademenev

Can’t figure out what’s happening here

 Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] 

Elixir 1.18.0 (compiled with Erlang/OTP 27)
iex(1)> File.open("/tmp/x.png", [:read, :binary], fn f -> IO.read(f, 1000) end)
{:ok,
 <<194, 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 7,
   39, 0, 0, 2, 195, 164, 8, 6, 0, 0, 0, 194, 165, 123, 57, 194, 133, 0, 0, 1,
   90, 105, 67, 67, 80, 73, 67, 67, ...>>}
iex(2)> File.read("/tmp/x.png")
{:ok,
 <<137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 7, 39, 0,
   0, 2, 228, 8, 6, 0, 0, 0, 165, 123, 57, 133, 0, 0, 1, 90, 105, 67, 67, 80,
   73, 67, 67, 32, 80, 114, 111, ...>>}
iex(3)>

PNG file starts with bytes 137, 80 and so on, but IO.read inside File.open inserts extra byte at the beginning

Showing Posts 1 to 3

ademenev

ademenev OP

Looks like any file containing bytes with MSB set gets screwed up

al2o3cr

al2o3cr

Use IO.binread - IO.read is specified to return a valid UTF-8 string

ademenev

ademenev OP

Thanks, that helps!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews