-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockIO.cs
47 lines (39 loc) · 1.15 KB
/
BlockIO.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using UnityEngine;
using System.Collections;
using System.IO;
namespace Uzu
{
public static class BlockIO
{
public static void WriteFile (string filePath, byte[] data)
{
using (FileStream resourceFile = new FileStream (filePath, FileMode.Create, FileAccess.Write)) {
Debug.Log ("Writing (" + ToByteStr (data.Length) + "): " + filePath);
resourceFile.Write (data, 0, data.Length);
}
}
public static byte[] ReadFile (string filePath)
{
using (MemoryStream ms = new MemoryStream()) {
using (FileStream resourceFile = new FileStream (filePath, FileMode.Open, FileAccess.Read)) {
Debug.Log ("Reading (" + ToByteStr (resourceFile.Length) + "): " + filePath);
byte[] data = new byte[resourceFile.Length];
resourceFile.Read (data, 0, (int)resourceFile.Length);
ms.Write (data, 0, (int)resourceFile.Length);
return ms.ToArray ();
}
}
}
#region Implementation.
private static string ToByteStr (long byteCount)
{
long kbCount = byteCount / 1024;
if (kbCount > 0) {
byteCount -= (kbCount * 1024);
return kbCount + "KB, " + byteCount + "B";
}
return byteCount + "B";
}
#endregion
}
}