Browse Source

added getTmpBytes

ncannasse 10 years ago
parent
commit
919688cac4
3 changed files with 24 additions and 0 deletions
  1. 7 0
      hxd/fmt/pak/FileSystem.hx
  2. 2 0
      hxd/fs/FileEntry.hx
  3. 15 0
      hxd/fs/LocalFileSystem.hx

+ 7 - 0
hxd/fmt/pak/FileSystem.hx

@@ -48,6 +48,13 @@ private class PakEntry extends FileEntry {
 		return pak.read(file.dataSize);
 	}
 
+	override function getTmpBytes() {
+		pak.seek(file.dataPosition, SeekBegin);
+		var tmp = hxd.impl.Tmp.getBytes(file.dataSize);
+		pak.readFullBytes(tmp, 0, file.dataSize);
+		return tmp;
+	}
+
 	override function open() {
 		if( openedBytes == null ) {
 			openedBytes = hxd.impl.Tmp.getBytes(file.dataSize);

+ 2 - 0
hxd/fs/FileEntry.hx

@@ -14,6 +14,8 @@ class FileEntry {
 
 	public function getBytes() : haxe.io.Bytes return null;
 
+	public function getTmpBytes() return getBytes();
+
 	public function open() { }
 	public function skip( nbytes : Int ) { }
 	public function readByte() : Int return 0;

+ 15 - 0
hxd/fs/LocalFileSystem.hx

@@ -114,6 +114,21 @@ private class LocalEntry extends FileEntry {
 		#end
 	}
 
+	override function getTmpBytes() {
+		#if air3
+		if( checkExists && !file.exists )
+			return haxe.io.Bytes.alloc(0);
+		var fs = new flash.filesystem.FileStream();
+		fs.open(file, flash.filesystem.FileMode.READ);
+		var bytes = hxd.impl.Tmp.getBytes(fs.bytesAvailable);
+		fs.readBytes(bytes.getData());
+		fs.close();
+		return bytes;
+		#else
+		return sys.io.File.getBytes(file);
+		#end
+	}
+
 	override function getBytes() : haxe.io.Bytes {
 		#if air3
 		if( checkExists && !file.exists )