# Possibly confusing or inconsistent methods for read()

**URL:** https://discourse.julialang.org/t/possibly-confusing-or-inconsistent-methods-for-read/2102
**Category:** New to Julia
**Tags:** documentation, binaryio
**Created:** [February 14, 2017, 6:38pm UTC](https://discourse.julialang.org/t/possibly-confusing-or-inconsistent-methods-for-read/2102 "2017-02-14T18:38:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![oatlzzvztd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oatlzzvztd/32/3285_2.png) [@oatlzzvztd](https://discourse.julialang.org/u/oatlzzvztd)
#### Post date: [February 14, 2017, 6:38pm UTC](https://discourse.julialang.org/t/possibly-confusing-or-inconsistent-methods-for-read/2102/1 "2017-02-14T18:38:27Z")

</div>

Ran into this gotcha today and felt like I should flag it down for anyone else who runs into it.

From the v0.5.1 docs, read() has the following two methods:

> **read(stream::IO, T, dims)**

> Read a series of values of type `T` from `stream`, in canonical binary representation. dims is either a tuple or a series of integer arguments specifying the size of the `Array{T}` to return.

> **read(s::IO, nb=typemax(Int))**

> Read at most `nb` bytes from `s`, returning a `Vector{UInt8}` of the bytes read.

What confused me here is that the first method _must_ read `prod(dims) * sizeof(T)` bytes, whereas the second method _may_ read at most `nb` bytes. In the 1D case, `read(stream, nb)` looks very similar to `read(stream, T, numT)` (and even does the same thing when `T == UInt8`.)

To get around this, use the second method in coordination with `reinterpret()`, like so:

```julia
temp = read(stream, numT * sizeof(T))
data = reinterpret(T, temp) # possibly followed by reshaping.

```

I’m open to other suggestions for reading at most `numT` bitstypes from a stream.
