Questions tagged [fwrite]

fwrite stands for file write. It is a function available with PHP, C, C++, etc. for writing the contents of string to the file stream pointed to by handle.

fwrite stands for file write. It is a function available with PHP, C, C++, etc. for writing the contents of string to the file stream pointed to by handle.

PHP fwrite

Visual Studio fwrite

C++ fwrite

1762 questions
16
votes
3 answers

What is the best way to write a large file to disk in PHP?

I have a PHP script that occasionally needs to write large files to disk. Using file_put_contents(), if the file is large enough (in this case around 2 MB), the PHP script runs out of memory (PHP Fatal error: Allowed memory size of ######## bytes…
Joe Lencioni
  • 10,231
  • 18
  • 55
  • 66
16
votes
5 answers

C program stuck on uninterruptible wait while performing disk I/O on Mac OS X Snow Leopard

One line of background: I'm the developer of Redis, a NoSQL database. One of the new features I'm implementing is Virtual Memory, because Redis takes all the data in memory. Thanks to VM Redis is able to transfer rarely used objects from memory to…
antirez
  • 18,314
  • 5
  • 50
  • 44
15
votes
2 answers

Memory Mapped files and atomic writes of single blocks

If I read and write a single file using normal IO APIs, writes are guaranteed to be atomic on a per-block basis. That is, if my write only modifies a single block, the operating system guarantees that either the whole block is written, or nothing at…
Martin Probst
  • 9,497
  • 6
  • 31
  • 33
14
votes
2 answers

how to write an integer to a file (the difference between fprintf and fwrite)

I've been trying to write an integer to a file (open mode is w). fprintf wrote it correctly but fwrite wrote gibberish: int length; char * word = "word"; counter = strlen(word); fwrite(&length, sizeof(int), 1, file); fwrite(word, sizeof(char),…
Shai Balassiano
  • 997
  • 2
  • 10
  • 21
12
votes
3 answers

disk write performance in golang

In the following code, I write messages to a file using bufio in golang. My disk I/O speed is about 1000M/s. Strangely, when the size of the written file is less than 20G, the writing speed is about 800M~900M per second, a little bit less than the…
Nature.Li
  • 345
  • 1
  • 3
  • 11
12
votes
2 answers

Writing an ASCII string as binary in python

I have a ASCII string = "abcdefghijk". I want to write this to a binary file in binary format using python. I tried following: str = "abcdefghijk" fp = file("test.bin", "wb") hexStr = "".join( (("\\x%s") % (x.encode("hex"))) for x in…
aMa
  • 629
  • 3
  • 10
  • 19
12
votes
5 answers

Checking for success of fwrite in C, perror

With fwrite returning the number of successful elements written to the file, by saying: if (!(fwrite(...))) { fprintf(stderr, "Failure"); //perror(???) I sometimes see code that says perror here and I don't know //exactly what this…
Crystal
  • 28,460
  • 62
  • 219
  • 393
12
votes
1 answer

Error writing a file with file.write in Python. UnicodeEncodeError

I have never dealt with encoding and decoding strings, so I am quite the newbie on this front. I am receiving a UnicodeEncodeError when I try to write the contents I read from another file to a temporary file using file.write in Python. I get the…
user2643864
  • 641
  • 3
  • 11
  • 24
11
votes
1 answer

How to do atomic file replacement?

What's the recommended way to replace a file atomically in Python? i.e. if the Python script is interrupted, there is a power outage etc. files do not have a high probability of ending up in an inconsistent state (half written to the disk). A…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
11
votes
9 answers

fwrite() and UTF8

I am creating a file using php fwrite() and I know all my data is in UTF8 ( I have done extensive testing on this - when saving data to db and outputting on normal webpage all work fine and report as utf8.), but I am being told the file I am…
Lizard
  • 43,732
  • 39
  • 106
  • 167
11
votes
4 answers

How can i specify encode in fwrite() for export csv file R?

Since fwrite() cannot apply encoding argument , how can i export csv file in specific encode as fast as fwrite() ? (fwrite() is the fastest function within my acknowledgement so far) fwrite(DT,"DT.csv",encoding = "UTF-8") Error in fwrite(DT,…
rane
  • 901
  • 4
  • 12
  • 24
11
votes
1 answer

createWriteStream vs writeFile?

What is the basic difference between these two operations ? someReadStream.pipe(fs.createWriteStream('foo.png')); vs someReadStream.on('data', function(chunk) { blob += chunk } ); someReadStream.on('end', function() { fs.writeFile('foo.png', blob)…
Randy
  • 153
  • 1
  • 2
  • 7
10
votes
1 answer

Is there a way to write formatted text from Python?

If you are writing to a file with python, is there any way to make certain parts of the text bold, italic, or underlined ? i tried: test = '/location/tester.rtf' out_file = open(test,'w') out_file.write('is this {\bold}?') out_file.close() #thanks…
O.rka
  • 29,847
  • 68
  • 194
  • 309
9
votes
4 answers

Overwrite file on server (PHP)

I am making an Android application that need to be able to push files onto a server. For this I'm using POST and fopen/fwrite but this method only appends to the file and using unlink before writing to the file has no effect. (file_put_contents has…
Luke Pring
  • 992
  • 3
  • 11
  • 16
9
votes
2 answers

Is fwrite faster than WriteFile in windows?

I have always thought that WriteFile is more efficient than fwrite, because fwrite calls down to WriteFile internally, but the following test code show me that fwrite is faster significantly than WriteFile. fwrite costs 2 milliseconds while…
Frahm
  • 805
  • 2
  • 9
  • 16