Closing Files

Discussed in this topic: fd.close, fd.flush.

Files are closed using the fd.close method. The method is performed on a currently selected file (selection is made through the fd.filenum property). Attempting to invoke this method "on" a file number that did not have any opened file associated with it generates no error.

Proper file closing is only required if you made changes to the file. If you only read data from the file you don't have to bother closing it — you can open another file right "on" the same file number. Doing so on a file that was changed may cause some recent changes to be lost. To prevent this, use the fd.close method or fd.flush method. Note that fd.flush does not depend on the current fd.filenum value and works globally on any most recently changed file.

It is not necessary to use fd.flush if your disk operations are performed within a disk transaction.