PureFILE library : WinAPI based file functions

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

PureFILE library : WinAPI based file functions

Post by gnozal »

PureFILE library V1 (Last update : SEPT 10th 2008)

Overview

Code: Select all

This user library offers WinAPI based buffered file functions, usually faster than the genuine Purebasic ones, but with a similar syntax.
Functions
PB3.94 : http://gnozal.ucoz.com/PureFILE.htm
PB4.0x : http://gnozal.ucoz.com/PureFILE_.htm

Example

Code: Select all

If PureFILE_ReadFile(#PB_Any, "C:\PureBasic393\Compilers\APIFunctionListing.txt")
  While PureFILE_NotEof()
    PureFILE_ReadString()
  Wend
  PureFILE_CloseFile()
EndIf
;
If PureFILE_ReadFile(1, "C:\PureBasic393\Compilers\APIFunctionListing.txt")
  If PureFILE_CreateFile(2, "C:\PureBasic393\Compilers\APIFunctionListing2.txt")
    *Buffer = AllocateMemory(50000)
    If *Buffer
      BytesRead = PureFILE_ReadData(1, *Buffer, 50000)
      While BytesRead
        BytesWritten = PureFILE_WriteData(2, *Buffer, BytesRead)
        BytesRead = PureFILE_ReadData(1, *Buffer, 50000)
      Wend
      PureFILE_CloseFile(1)
      PureFILE_CloseFile(2)
      FreeMemory(*Buffer)
    EndIf
  EndIf
EndIf
;
If PureFILE_ReadTextFile(#PB_Any, "C:\PureBasic393\Program\bigtextfile.txt")
  While PureFILE_NotEof()
    Line.s = PureFILE_ReadString()
  Wend
  PureFILE_CloseFile()
  Debug Line
EndIf
Download :
Only available for Purebasic Windows x86 (v3.9x-4.3x)
PB3.94 : http://gnozal.ucoz.com/PureFILE.zip
PB4.00-4.10 : http://gnozal.ucoz.com/PureFILE_.zip
PB4.20 : http://gnozal.ucoz.com/PureFILE___.zip
PB4.30 : http://gnozal.ucoz.com/PureFILE_430.zip
Last edited by gnozal on Wed Dec 10, 2008 11:24 am, edited 13 times in total.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Disclaimer
The goal of this library is to provide some WinAPI based file functions usually faster than the genuine ones, but with a similar syntax.
It is based on GPI's jaPBe source code (thanks). There is no FastFile code included, and it is not intended to compete with Ring's library.
I simply find it usefull.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Post by Justin »

if you want something usefull use handles like the winapi does and forget the id pb style way
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

appreciate your efforts gnozal, opensource is fine as long as there are not too many strings atached/or you need a law degree to understand the licence, eg LGPL.
as for me, i don't touch GPL source at all, much prefer public domain. :)
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

As Jack said re sources/GPL, etc (on another thread) .. either give it away freely or keep it hidden.

(I bet he says that to all the girls)!

GPL does suck.

That said, closed libs are a liability for the user, as we have seen. Often.

It is not just the potential for the lib to be malignant, deliberately or otherwise.

With all the best intentions in the world, the author cannot release the sources if they're suddenly dead - "Oops" said the busdriver!

And then the user is stuck if the lib gets left behind. It's either a rewrite of the code or sticking with an older version of PB for some apps.

Better a DLL, and best is open source.
@}--`--,-- A rose by any other name ..
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Dare2 wrote:With all the best intentions in the world, the author cannot release the sources if they're suddenly dead - "Oops" said the busdriver!
Yes, but it's also true for commercials libs like Purevision Gadgets and even Purebasic.
Dare2 wrote:It's either a rewrite of the code or sticking with an older version of PB for some apps. Better a DLL
If you have an obsolete lib you can embed the functions in a DLL using an older PB version and then use it with newer PB versions.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Points taken!
:)

(I'd never thought of the embedding bit!)

But I'll stick to what I can see. And understand. The latter limits me quite a bit. :)
@}--`--,-- A rose by any other name ..
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Dare2 wrote: .. And understand. The latter limits me quite a bit.
yeah, you are quite stupid sometimes..




:lol:
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

thefool wrote:yeah, you are quite stupid sometimes..
:lol:
hehe. :P

* Note to self: Payback required! *
@}--`--,-- A rose by any other name ..
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Dare2 wrote: * Note to self: Payback required! *
damn! well, lets c if you "dare 2" do that :o
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Hallo,
i need a fast stuff for file dealing.
So, i'd like to know wich lib is faster; the Gnozal one or the Rings one? :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> I think PB functions don't have buffering, but I may be wrong

They do, and the buffer size can even be changed:

Code: Select all

Syntax
FileBuffersSize(#File, Size)

Description
Change the size of the buffers for the specified file. This method is available for advanced users, to allow to tune the file access performances. The default buffer size is 4096 bytes per file. If the 'Size' is put to 0, then all caching is disabled, and all write operations are immediately written to the disk.

Note: For performance reason, the buffer size should be kept large enough (1028 seems to be ok as minimum). When buffers are used, the information is really written to the disk once the cache buffer is full or when the file is closed. The FlushFileBuffers() command allow to force the write of the cache buffer at any time.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I don't think either will be faster than v4's native file functions as they have been improved immensely over 3.94. I look at those 3rd party libs as being more or less "obsolete" since v4. Someone could correct me if I'm wrong.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

The PureFILE library is faster than the genuine PB3.94 functions (I use it a lot).
But if you use PB4.00, you should use the genuine PB functions, since they are now buffered. The PB4.00 PureFILE version is only provided for compatibility reasons.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thanks,
but i do a compare file program with pb4.0 and the " fc.exe /B " command (which comes with windows) is faster :o
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply