PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] How to read a portion of a file in Elixir (or Erlang)?

 May 18, 2022     elixir, erlang, file, partial     No comments   

Issue

How can we read only a selected portion of a file?

Like this: Read(file, start, length)


Solution

You can use :file.position/2 and :file.read/2.

With:

$ seq 10 > 10.txt

and code:

{:ok, file} = :file.open("10.txt", [:read, :binary])
:file.position(file, 5)
IO.inspect :file.read(file, 10)

The output is:

{:ok, "\n4\n5\n6\n7\n8"}

That's 10 bytes starting at the 6th byte.



Answered By - Dogbert
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing