Questions tagged [file-handling]

File handling refers to the set of tools, functions, and libraries to work with files and file handles. Creating, writing, appending, moving, and deleting files fall in this domain.

File handling refers to the set of tools, functions, and libraries to work with files and file handles. Creating, writing, appending, moving, and deleting files fall in this domain.

172 questions
247
votes
13 answers

Is it a bad practice to store large files (10 MB) in a database?

I am currently creating a web application that allows users to store and share files, 1 MB - 10 MB in size. It seems to me that storing the files in a database will significantly slow down database access. Is this a valid concern? Is it better to…
B Seven
  • 3,155
133
votes
8 answers

Difference between '\n' and '\r\n'

Yes yes, I am aware that '\n' writes a newline in UNIX while for Windows there is the two character sequence: '\r\n'. All this is very nice in theory, but my question is why? Why the carriage return character is extra in Windows? If UNIX can do it…
sukhbir
  • 1,499
  • 2
  • 11
  • 9
82
votes
7 answers

Should temporary files be saved to /tmp or the current working directory?

I have a program that needs to generate temporary files. It is written for cluster machines. If I saved those files to a system-wide temporary directory (eg: /tmp), some users complained the program failed because they didn't have proper access to…
SmallChess
  • 1,246
72
votes
6 answers

Should I pass in filenames to be opened, or open files?

Suppose I have a function that does things with a text file - for example reads from it and removes the word 'a'. I could either pass it a filename and handle the opening/closing in the function, or I could pass it the opened file and expect that…
Dan Oberlam
  • 1,291
  • 1
  • 9
  • 22
53
votes
3 answers

What is the benefit of writing to a temp location, And then copying it to the intended destination?

I am writing an application that works with satellite images, and my boss asked me to look at some of the commercial applications, and see how they behave. I found a strange behavior and then as I was looking, I found it in other standard…
24
votes
2 answers

Why would anyone use multipart/form-data for mixed data and file transfers?

I'm working in C# and doing some communication between 2 apps I'm writing. I have come to like the Web API and JSON. Now I am at the point where I am writing a routine to send a record between the two servers that includes some text data and a file.…
Ian
  • 425
22
votes
1 answer

How do I test a file reader?

I am working on a project with a few file formats. Some formats are specified by .xsds, others by documentation on their respective websites, and some are custom in-house formats that have no documentation. Mwahahahaha. What's the problem? I would…
20
votes
4 answers

Using flat files vs database/API as a transport between a frontend and backend

I've got an application which has generated a rather heated discussion between a couple of the developers. Basically, it's split into a web layer and a backend layer. The web layer collects information by a simple web form, stashes this data as a…
20
votes
3 answers

What is a good design for allowing backwards compatibility of files between different versions of software?

What is a good design for allowing backwards compatibility of a file type between different versions of software? For instance, how does microsoft get word 2007, 2010 and 2013 etc... to all open docx files, but different editions can save more /…
JJBurgess
  • 301
20
votes
7 answers

Is it necessary to read every single byte to check if a copied file is identical to the original?

I recently learned of a program called Total Commander. It's a Windows Explorer replacement and has its own stuff to copy files. To check whether the files are identical, instead of calculation a CRC, it literally checks every single byte, one at a…
Koen027
  • 303
18
votes
5 answers

What's the best practice for naming uploaded images?

Suppose I have a form in my web application where users can upload a profile picture. I've got few requirements about file size, dimensions etc, but when the user uploads the image, how should I name them on my system? I suppose it would need to be…
16
votes
5 answers

Test Driven Development: A good/accepted way to test file system operations?

I am working on a project at the moment that generates a table (among other things) based on the contents of a file-system, and in turn does some meta-data modifications on the things it finds. The question is: how should tests be written around…
15
votes
7 answers

Best way to handle delimited files

So typically a CSV file uses a comma and the return character as it's field and line delimiters. This runs into obvious problems with text which can contain both these characters. Obviously there are options there (escaping them) but how do people…
Jon Hopkins
  • 22,774
13
votes
1 answer

Base64 in Json: Is it a Good Idea for Rest API?

I am developing a Rest API, and I am asking myself: Is it a good Idea to put base64 encoded data in Json, e.g. for file uploads? What if the base64 contains some of {,},: characters and breaks the json content? If is not a good idea, what…
Dimitrios Desyllas
  • 481
  • 2
  • 4
  • 17
12
votes
5 answers

PHP file_put_contents File Locking

The Senario: You have a file with a string (average sentence worth) on each line. For arguments sake lets say this file is 1Mb in size (thousands of lines). You have a script that reads the file, changes some of the strings within the document (not…
hozza
  • 313
  • 1
  • 3
  • 12
1
2 3
11 12