Talk:Read entire file

From Rosetta Code

Encoding selection

The task description mentions "encoding selection". What has encoding got to do with reading entire file? If you read a file into memory, you just read the file. Encoding is something to be considered when you are manipulating the data. I assume the "encoding" refers to text encoding. However, the file may be a picture file, or binary data or whatever. --PauliKL 16:09, 6 March 2013 (UTC)

The primary objective is to read a file into a string, not necessarily into memory. Some languages are encoding-aware and behave accordingly. Ruby, for instance:
<lang Ruby>['ASCII', 'UTF-8'].map { |e| File.open('foo', encoding: e).read.size }
  1. => [3, 1]</lang>Isopsephile 16:43, 6 March 2013 (UTC)