LoginSignup
0
0

More than 5 years have passed since last update.

バイト指定のテキストファイルのつくりかた

Last updated at Posted at 2015-10-21

小ネタです。とある案件で、バイト指定のjsファイル(たとえば10MBとか)を作成したくてちょっと調べたのでそのメモ。
具体的にいうと、ベースとなるjsファイルがあって、それをサイズだけ水増しすることが目的です。
手順は以下の通りです。
1. ベースとなるjsファイルを作成 (sample.js)
2. 100MBくらいのコメントアウトされただけのテキストファイルを作成 (comment.txt)
3. head -c でバイト指定して comment.txt から抜き出し (commentXXMB.txt)1

$ head -c 10485760 comment.txt > comment10MB.txt
  1. cat コマンドで sample.js と comentXXMB.txt をつなげて index.js を作成
$ cat sample.js comment10MB.txt > index.js

という感じです。ホントに正確にサイズ指定する場合は、sample.jsのバイト数をheadの-cオプションで指定する値から差し引いてください。あとは、tail で正しくコメントアウトされているか確認しておけばOKでしょう。


  1. 10485760 Byte (=1024*1024*10) 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0