Skip to content

Instantly share code, notes, and snippets.

@jdmunro
Created January 22, 2009 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdmunro/50606 to your computer and use it in GitHub Desktop.
Save jdmunro/50606 to your computer and use it in GitHub Desktop.
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