]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Utilities.h
...
[cpPlugins.git] / lib / cpPlugins / Utilities.h
index b919c202adbc4f15fc38696a0161a800fdd2d82e..ff033b4b62277e674a8c85cded12860f8f6e19af 100644 (file)
@@ -87,26 +87,6 @@ namespace cpPlugins
     return( res );
   }
 
-  // -----------------------------------------------------------------------
-  inline bool ReadFileIntoBuffer(
-    std::string& buffer, const std::string& fname
-    )
-  {
-    buffer = "";
-    std::ifstream file_stream( fname.c_str( ) );
-    if( !file_stream )
-      return( false );
-    file_stream.seekg( 0, std::ios::end );
-    buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
-    file_stream.seekg( 0, std::ios::beg );
-    buffer.assign(
-      ( std::istreambuf_iterator< char >( file_stream ) ),
-      std::istreambuf_iterator< char >( )
-      );
-    file_stream.close( );
-    return( true );
-  }
-
   // -----------------------------------------------------------------------
   inline std::string CanonicalPath( const std::string& path )
   {
@@ -128,6 +108,42 @@ namespace cpPlugins
     return( ret );
   }
 
+  // -----------------------------------------------------------------------
+  inline bool WriteBufferToFile(
+    const std::string& buffer, const std::string& fname
+    )
+  {
+    std::ofstream file_stream(
+      CanonicalPath( fname ).c_str( ), std::ofstream::binary
+      );
+    if( !file_stream )
+      return( false );
+    file_stream.write( buffer.c_str( ), buffer.size( ) );
+    return( true );
+  }
+
+  // -----------------------------------------------------------------------
+  inline bool ReadFileIntoBuffer(
+    std::string& buffer, const std::string& fname
+    )
+  {
+    buffer = "";
+    std::ifstream file_stream(
+      CanonicalPath( fname ).c_str( ), std::ifstream::binary
+      );
+    if( !file_stream )
+      return( false );
+    file_stream.seekg( 0, std::ios::end );
+    buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
+    file_stream.seekg( 0, std::ios::beg );
+    buffer.assign(
+      ( std::istreambuf_iterator< char >( file_stream ) ),
+      std::istreambuf_iterator< char >( )
+      );
+    file_stream.close( );
+    return( true );
+  }
+
 } // ecapseman
 
 #endif // __CPPLUGINS__UTILITY__H__