Talk:Read entire file: Difference between revisions
Content added Content deleted
(Encoding selection) |
|||
Line 5: | Line 5: | ||
I assume the "encoding" refers to text encoding. However, the file may be a picture file, or binary data or whatever. |
I assume the "encoding" refers to text encoding. However, the file may be a picture file, or binary data or whatever. |
||
--[[User:PauliKL|PauliKL]] 16:09, 6 March 2013 (UTC) |
--[[User:PauliKL|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 } |
|||
# => [3, 1]</lang>[[User:Isopsephile|Isopsephile]] 16:43, 6 March 2013 (UTC) |
Revision as of 16:43, 6 March 2013
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 }
- => [3, 1]</lang>Isopsephile 16:43, 6 March 2013 (UTC)