Created
January 22, 2009 16:47
-
-
Save jdmunro/50606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MemoryStream GetFileStream( string sFile ) | |
{ | |
if( !this.Exists(sFile) ) { | |
System.Console.WriteLine("Error loading non-existent file (GetFileStream)"); | |
return null; | |
} | |
// Load the file from the search path. | |
IntPtr fh = IntPtr.Zero; | |
if( ( fh = Fs.PHYSFS_openRead(sFile) ) == IntPtr.Zero ) { | |
System.Console.WriteLine("Error opening file for reading (GetFileStream)."); | |
return null; | |
} | |
System.Console.WriteLine("Loaded file (" + sFile + "," + | |
Fs.PHYSFS_fileLength(fh) + ")."); | |
// Create a memory stream. | |
byte[] file; | |
Fs.PHYSFS_read(fh,out file,1,(uint)Fs.PHYSFS_fileLength(fh)); | |
MemoryStream ms = new MemoryStream(file); | |
// Close the file handle. | |
Fs.PHYSFS_close(fh); | |
if( ms.Length == 0 ) { | |
System.Console.WriteLine("Error creating memory stream from file (GetFileStream)"); | |
return null; | |
} | |
return ms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment