[oR]
2.2 Overview A file, in the strictest sense of the word, is a set of sectors on a disk, identified under a unique file name. In many systems and languages, at least at a low level, you treat a file just that way�you can actually read off buffered or unbuffered sectors of information in sector-sized chunks. Most programming languages and operating systems also offer a character-based (as well as a structure-based) abstraction that allows you to deal with information at a more natural level.
In the 32-bit API, you think of a file as a collection of bytes. This is identical to the low-level access paradigm provided by UNIX. You can seek to any byte offset and read a block of bytes of any size. If you want to work at a higher level of abstraction�for example, thinking of the file as a set of text lines�you use the libraries in a language like C or C++ to handle the abstraction for you. One of the nice things about the low-level file-access functions in the API is that they are fairly easy to understand and use.
Figure 2.1 shows two ways that you will access files in Windows. Files typically contain either text, or binary data in the form of structures stored directly onto the disk. You can use the ReadFile and WriteFile functions to access these characters or structures. If you have ever used the fread and fwrite functions in <stdio.h> you will find the use of these API functions very similar.
Figure 2.1. Text files and files of structures
These same ReadFile and WriteFile functions appear throughout the API in a variety of roles. You will use them, for example, to read from and write to communication ports and the network. In these applications you will also be able to think of the data in terms of single characters or structures.
A number of functions in the API allow you to gather information about a file once you open it. For example, given an open file, you can determine its size, type, creation times, and so on. You can also use the API functions to move, copy, and delete files.
|
No comments:
Post a Comment