home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 24.17 Buffered read/write
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- #define BUFFER_SIZE 4096
-
- STATIC buffer :=""
-
- function bread(nHandle,nBytes)
- LOCAL tmp
- if nBytes > len(buffer)
- tmp := buffer
- buffer := space(BUFFER_SIZE)
- fread(nHandle,@buffer,BUFFER_SIZE)
- buffer := tmp+buffer
- endif
- tmp := substr(buffer,1,nBytes)
- buffer := substr(buffer,nBytes+1,BUFFER_SIZE)
- return tmp
-
-
- function bwrite(nHandle,cString)
- LOCAL x:=.T.
- buffer := buffer+cString
- if len(buffer) >= BUFFER_SIZE
- x := (fwrite(nHandle,buffer)=len(buffer))
- buffer:=""
- endif
- return x
-
- // end of file CHP2417.PRG
-