質問編集履歴
1
ご返信いただき、ありがとうございます。「試したこと」に、使用クレートを追記しました。また、少しコードを修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,15 +19,21 @@
|
|
19
19
|
# 以下の”text”のType
|
20
20
|
# encoding_rs_io::DecodeReaderBytes<std::fs::File, std::vec::Vec<u8>>
|
21
21
|
|
22
|
+
let mut outfile =
|
22
|
-
|
23
|
+
BufWriter::new(fs::File::create("test.txt").unwrap());
|
23
|
-
let reader = BufReader::new(text);
|
24
|
+
let mut reader = BufReader::new(text);
|
24
25
|
|
25
|
-
|
26
|
+
loop {
|
26
|
-
let
|
27
|
+
let mut buf = String::new();
|
28
|
+
let num_bytes = reader.read_line(&mut buf).unwrap();
|
27
29
|
|
28
30
|
## UTF-8 → Shift-JISに変換する処理 ##
|
29
31
|
|
32
|
+
if num_bytes == 0 {
|
33
|
+
break;
|
34
|
+
} else {
|
30
|
-
|
35
|
+
outfile.write(buf.as_bytes()).unwrap();
|
36
|
+
}
|
31
37
|
}
|
32
38
|
|
33
39
|
```
|
@@ -37,8 +43,18 @@
|
|
37
43
|
上手くいっておりません。decodeの第一引数には&[u8]をセットしないといけないことは分かったのですが、
|
38
44
|
この処理をどのように使用すればよいのかがよく分かっていません。
|
39
45
|
|
40
|
-
let
|
46
|
+
let buf = WINDOWS_31J.decode(buf, DecoderTrap::Strict).unwrap();
|
41
47
|
|
48
|
+
・使用したクレート
|
49
|
+
use std::fs;
|
50
|
+
use std::fs::File;
|
51
|
+
use std::*;
|
52
|
+
use std::io::{self, BufRead, BufReader, BufWriter, Write};
|
53
|
+
use std::path::Path;
|
54
|
+
use encoding_rs::SHIFT_JIS;
|
55
|
+
use encoding_rs_io::DecodeReaderBytesBuilder;
|
56
|
+
|
57
|
+
|
42
58
|
### 補足情報(FW/ツールのバージョンなど)
|
43
59
|
|
44
60
|
・Windows10
|