これが私が思いついたものです。以下のコードは int[1000][10000] を作成し、BinaryFormatter を使用して 2 つのファイル (1 つは圧縮され、もう 1 つは圧縮されていない) に書き込みます。
圧縮されたファイルは 1.19 MB (1,255,339 バイト) で、解凍されたファイルは 38.2 MB (40,150,034 バイト) です。
int width = 1000;
int height = 10000;
List<int[]> list = new List<int[]>();
for (int i = 0; i < height; i++)
{
list.Add(Enumerable.Range(0, width).ToArray());
}
int[][] bazillionInts = list.ToArray();
using (FileStream fsZ = new FileStream("c:\\temp_zipped.txt", FileMode.Create))
using (FileStream fs = new FileStream("c:\\temp_notZipped.txt", FileMode.Create))
using (GZipStream gz = new GZipStream(fsZ, CompressionMode.Compress))
{
BinaryFormatter f = new BinaryFormatter();
f.Serialize(gz, bazillionInts);
f.Serialize(fs, bazillionInts);
}
これを行うためのより良い/簡単な方法は考えられません。圧縮されたバージョンはかなりきついです。
BinaryFormatter + GZipStream を使用します。何かをカスタムするのはまったく楽しくありません。
[MG による編集] 編集によって気分を害されないことを願っていますが、均一に繰り返される Range(0,width) は物事を大きく歪めています。への変更:
int width = 1000;
int height = 10000;
Random rand = new Random(123456);
int[,] bazillionInts = new int[width, height];
for(int i = 0 ; i < width;i++)
for (int j = 0; j < height; j++)
{
bazillionInts[i, j] = rand.Next(50000);
}
そして試してみてください。temp_notZipped.txt40MB、temp_zipped.txt62MB で表示されます。あまり魅力的ではない...