I was thinking of delegating stuff to IO.read when dealing with lines On Thu, 12 May 2016 15:08:15 +0200 José Valim <jose.va...@plataformatec.com.br> wrote:
> Not in your example but if you want to do it per line, then yes. > > On Thursday, May 12, 2016, Charles Okwuagwu <okwuagwu...@gmail.com> > wrote: > > > def read(file, start, length) do > > {ok, f} = :file.open(file, [:binary]) > > * {ok**, data} = :file.pread(f, start,** length)* > > :file.close(f) > > dataend > > > > We are not reading the whole file, or are we? *:file.pread/3* > > > > > > On Thursday, May 12, 2016 at 1:36:05 PM UTC+1, José Valim wrote: > >> > >> We need to consider that performance wise they are quite > >> different. We can move the cursor when reading lines, we can't > >> move the cursor when reading bytes. We would actually need to load > >> the file into Elixir. It would probably be more interesting to add > >> a File.position instead of hiding the underlying behaviour. > >> > >> > >> *José Valim* > >> www.plataformatec.com.br > >> Skype: jv.ptec > >> Founder and Director of R&D > >> > >> On Thu, May 12, 2016 at 2:25 PM, eksperimental > >> <eksper...@autistici.org> wrote: > >> > >>> Hi Charles, > >>> thank you for your proposal. > >>> > >>> I think it could be an interesting addition. But rather than just > >>> a convenience function, make it behave more like its IO > >>> conterpart: IO.read/2 > >>> > >>> Where you can pass the byte length, or :line. > >>> Because sometimes is not about the bytes, but about the > >>> information held in a certain number of lines in the file. > >>> > >>> I'm thinking something like > >>> > >>> File.read(file_path, :line, 1) > >>> > >>> # or to read the first five lines > >>> File.read(file_path, :line, 1..5) > >>> > >>> I would like to know how the rest of the list feels about it. > >>> > >>> > >>> On Mon, 9 May 2016 10:36:15 -0700 (PDT) > >>> Charles Okwuagwu <okwua...@gmail.com> wrote: > >>> > >>> > Can we have this convenience as a function in the File module? > >>> > > >>> > read(file, start, length) > >>> > > >>> > > >>> > > >>> > http://stackoverflow.com/q/37121605/44080 > >>> > > >>> > The suggested solution is not immideiately obvious > >>> > > >>> > {:ok, file} = :file.open(source_file, [:read, :binary]) > >>> > > >>> > :file.position(file, 5) # start_position = 5 > >>> > > >>> > :file.read(file, 10) # bytes to read = 10 > >>> > > >>> > > >>> > > >>> > >>> -- > >>> You received this message because you are subscribed to the Google > >>> Groups "elixir-lang-core" group. > >>> To unsubscribe from this group and stop receiving emails from it, > >>> send an email to elixir-lang-co...@googlegroups.com. > >>> To view this discussion on the web visit > >>> https://groups.google.com/d/msgid/elixir-lang-core/20160512192534.35e62698.eksperimental%40autistici.org > >>> . > >>> For more options, visit https://groups.google.com/d/optout. > >>> > >> > >> > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20160512203836.25224779.eksperimental%40autistici.org. For more options, visit https://groups.google.com/d/optout.