回答編集履歴

2

追記

2020/08/30 05:32

投稿

AkitoshiManabe
AkitoshiManabe

スコア5434

test CHANGED
@@ -27,3 +27,71 @@
27
27
  ----
28
28
 
29
29
  CODEPEN [FileReaderでダンプ表示](https://codepen.io/AkitoshiManabe/pen/YzqQZgV?editors=1010)
30
+
31
+
32
+
33
+ 追記)
34
+
35
+ コールバックによるネストが読みにくい場合、機能を細分化して実装しても良いかもしれません。
36
+
37
+ ```javascript
38
+
39
+ function convertArrayBufferToHexArray (buf) {
40
+
41
+ let
42
+
43
+ u = new Uint8Array(buf),
44
+
45
+ r = new Array(u.length),
46
+
47
+ i = u.length
48
+
49
+ ;
50
+
51
+ while ( i-- )
52
+
53
+ r[i] = u[i].toString(16).padStart(2,"0");
54
+
55
+ return r;
56
+
57
+ }
58
+
59
+
60
+
61
+ function convertHexArrayToDumpData (hexChrs) {
62
+
63
+ return hexChrs.reduce( function(a,c,i) {
64
+
65
+ let m = i % 16; // modulo
66
+
67
+ if( i && m === 0 ) a += "\n";
68
+
69
+ a += (m === 0 ? "": " ") + c;
70
+
71
+ return a;
72
+
73
+ },"");
74
+
75
+ }
76
+
77
+
78
+
79
+ // 以下、ユーザ関数の動作確認
80
+
81
+ var sample = "2020 August hello world".match(/./g).map(s => s.charCodeAt(0));
82
+
83
+ console.log( sample );
84
+
85
+ var buf = new Uint8Array( sample ).buffer; // ArrayBuffer
86
+
87
+ console.log( buf );
88
+
89
+ var rslt = convertArrayBufferToHexArray(buf);
90
+
91
+ console.log( rslt );
92
+
93
+ var dump = convertHexArrayToDumpData(rslt);
94
+
95
+ console.log( dump );
96
+
97
+ ```

1

加筆

2020/08/30 05:32

投稿

AkitoshiManabe
AkitoshiManabe

スコア5434

test CHANGED
@@ -16,7 +16,9 @@
16
16
 
17
17
  1. ``input[type="file"]`` のイベントで FileList を取得
18
18
 
19
+ 2. ``input[type="file"]``選択後のプロパティ``files``(FileList) から File を取得
20
+
19
- 2. FileList から File を取得
21
+ (ファイルが1つの場合も、FileListとして渡される)
20
22
 
21
23
  3. FileReader で内容を読む
22
24