Questions tagged [fread]

A binary-safe file read function in C/C++/PHP that returns the specified number of bytes from a stream. Also a fast csv parser in R's data.table package.

References:

1613 questions
6
votes
3 answers

set utf-8 encoding for fread fwrite

hi i use this code read and write text in file . $d = fopen("chat.txt", "r"); $content=fread($d,filesize('chat.txt')); $bn=explode('||',$content); foreach($bn as $bn) echo $bn.'
'; and $d = fopen("chat.txt", "a"); $c=$_GET['c']; …
behzad n
  • 239
  • 3
  • 5
  • 15
5
votes
1 answer

fread timeout with 'mod_fcgid: read timeout from pipe'

I have an issue with a URL my application is trying to access timing out. I am trying to catch this timeout and to solve this problem am using this code: $timeout = 120; if(false == $handle = @fsockopen($host, $port, $errno, $errstr,…
Drew
  • 1,687
  • 5
  • 25
  • 46
5
votes
3 answers

What's the best way to read from and then overwrite file contents in php?

What's the cleanest way in php to open a file, read the contents, and subsequently overwrite the file's contents with some output based on the original contents? Specifically, I'm trying to open a file populated with a list of items (separated by…
Phillip
  • 5,366
  • 10
  • 43
  • 62
5
votes
1 answer

Is there an equivalent of R’s data.table fread cmd keyword in pandas?

One very useful aspect of R’s data.table reading workhorse “fread” is the “cmd” keyword with which one can programmatically build a shell command and pass it to fread to read the output of the shell command in as a data.table. This is very powerful…
Palace Chan
  • 8,845
  • 11
  • 41
  • 93
5
votes
0 answers

Readahead effect on Linux fread()

I have a problem with readahead performance of a large binary file. My strategy is Read a fixed size chunk from the large binary file with fread(). (e.g. 10MB) Sleep for n milliseconds with usleep() just for readahead performance measuring. Repeat…
Yuf
  • 59
  • 1
5
votes
2 answers

Changing Data types of dataframe columns based on template with matching columns in R

I have 2 dataframes. Template - I will be using data types from this data frame. df - I want to change datatypes of this data frame based on template. I want to change data types of second dataframe based on first. Lets suppose I have below data…
Rushabh Patel
  • 2,672
  • 13
  • 34
5
votes
4 answers

Difference between readline vs fread/fgets in php

I have always used readline in my console commands before, but today I've come across the fread and fgets functions and my question is: what is the difference in using these two approaches: // first $inputLine = readline(); // second $inputLine =…
hvertous
  • 1,133
  • 11
  • 25
5
votes
1 answer

I want to interpret stdin as a binary file. Why is freopen failing on Windows?

TL;DR: Why does freopen(NULL, "rb", stdin) always fail on Windows? I'm trying to re-implement a base64 encoder in C that takes input from stdin and outputs the encoded equivalent into stdout. I had a problem in my previous post where fread was…
James Ko
  • 32,215
  • 30
  • 128
  • 239
5
votes
3 answers

Why does fread() in c read extra '#newlines' characters?

while I am trying to copy a file into string using fread() ,I am getting extra characters from file which is exactly equal to number of new lines. Here is my code: #include #include #define LEN 5000000 int main() { char *in…
phoenix
  • 87
  • 1
  • 8
5
votes
1 answer

Why is fread inserting carriage returns (\r) into data.table?

I am reading data from a .csv file using data.table::fread on a Windows 10 computer. The data reads in properly through read.csv; however, when I use fread to read in the data, all of the final columns in each row of the resulting data.table ends in…
Bob
  • 451
  • 1
  • 5
  • 12
5
votes
3 answers

C : Reading bytes from binary file

I am currently trying to read 256 bytes from a binary file and not getting any output (or errors) when running my program. I am a little confused where I am going wrong on this. Attempting to read each byte as a char and store as a char array of…
GregH
  • 5,125
  • 8
  • 55
  • 109
5
votes
1 answer

How to solve when fread is changing values of other integer variables

I'm having troubles in my college homework, I'm coding in c++ some sorting methods, and this just happened: int nufi = 0, d; cout << "nufi value: " << nufi << endl; d = fread(&item, sizeof(ItemType), 1, stripes[nStripe].arq); cout << "nufi…
Dk Ribeiro
  • 113
  • 8
5
votes
1 answer

php file_get_contents() get stuck in loading an image

As mentioned above, the php file_get_contents() function or even the fopen()/fread() combination stucks and times out when trying to read this simple image url: http://pics.redblue.de/artikelid/GR/1140436/fee_786_587_png but the same image is…
Imran Ahmed
  • 790
  • 1
  • 9
  • 22
5
votes
2 answers

Convert a data read in by fread function to data.frame

Assume that I have a sample csv file which has 3 rows and 4 columns. Say it looks like the following: name1 name2 name3 name4 11 12 13 14 21 22 23 24 31 32 33 34 I read it in using fread() (I am using the small sample…
StayLearning
  • 601
  • 2
  • 7
  • 18
5
votes
1 answer

How to use fread() with "https" url scheme?

In R Documentation for fread() it's said that "input" argument may be a URL starting http:// or file://. However in this "Introduction to data.table" vignette fread() is used with https: flights <-…
Krome
  • 371
  • 2
  • 10