file-size-splitter 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- file_size_splitter-0.1.0/PKG-INFO +89 -0
- file_size_splitter-0.1.0/README.md +64 -0
- file_size_splitter-0.1.0/pyproject.toml +57 -0
- file_size_splitter-0.1.0/setup.cfg +4 -0
- file_size_splitter-0.1.0/src/file_size_splitter/__init__.py +3 -0
- file_size_splitter-0.1.0/src/file_size_splitter/cli.py +66 -0
- file_size_splitter-0.1.0/src/file_size_splitter/py.typed +0 -0
- file_size_splitter-0.1.0/src/file_size_splitter/splitter.py +176 -0
- file_size_splitter-0.1.0/src/file_size_splitter.egg-info/PKG-INFO +89 -0
- file_size_splitter-0.1.0/src/file_size_splitter.egg-info/SOURCES.txt +12 -0
- file_size_splitter-0.1.0/src/file_size_splitter.egg-info/dependency_links.txt +1 -0
- file_size_splitter-0.1.0/src/file_size_splitter.egg-info/entry_points.txt +2 -0
- file_size_splitter-0.1.0/src/file_size_splitter.egg-info/top_level.txt +1 -0
- file_size_splitter-0.1.0/tests/test_splitter.py +117 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: file-size-splitter
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ファイルを指定されたサイズで分割し、分割したファイルを復元するツール
|
|
5
|
+
Author: momoandbanana22
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/momoandbanana22/file-size-splitter
|
|
8
|
+
Project-URL: Repository, https://github.com/momoandbanana22/file-size-splitter
|
|
9
|
+
Project-URL: Issues, https://github.com/momoandbanana22/file-size-splitter/issues
|
|
10
|
+
Keywords: file,split,restore,batch,powershell
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: System :: Archiving
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# File Size Splitter
|
|
27
|
+
|
|
28
|
+
ファイルを指定されたサイズで分割し、分割したファイルを復元するツール。
|
|
29
|
+
|
|
30
|
+
## 仕様
|
|
31
|
+
|
|
32
|
+
### 機能1: ファイル分割
|
|
33
|
+
- 指定されたファイルを、指定のサイズで分割する
|
|
34
|
+
- 分割サイズの指定方法:数値のみ(例: `10485760`)または単位付き(例: `10M`, `1G`)の両方に対応
|
|
35
|
+
- 単位: K(キロバイト)、M(メガバイト)、G(ギガバイト)
|
|
36
|
+
- 分割されたファイルには連番を付与する(例: `file.001`, `file.002`, ...)
|
|
37
|
+
- 分割情報を記録したメタデータファイルをJSON形式で生成する
|
|
38
|
+
- 出力先ディレクトリを指定可能(指定なしの場合は入力ファイルと同じディレクトリ)
|
|
39
|
+
- ストリーミング処理でメモリ効率よく分割する(大きなファイルでも対応)
|
|
40
|
+
|
|
41
|
+
### 機能2: 復元用スクリプト生成
|
|
42
|
+
- 分割時にBATファイル(Windows用)とPS1ファイル(PowerShell用)の両方を自動生成
|
|
43
|
+
- 生成されたスクリプトを使用して、分割されたファイルを元のファイルに復元する
|
|
44
|
+
- 復元時のファイル名はメタデータファイルから自動取得
|
|
45
|
+
|
|
46
|
+
## 使用方法
|
|
47
|
+
|
|
48
|
+
### ファイル分割
|
|
49
|
+
```bash
|
|
50
|
+
file-size-splitter <入力ファイル> <分割サイズ> [-o 出力ディレクトリ]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**例:**
|
|
54
|
+
```bash
|
|
55
|
+
# 10MBごとに分割
|
|
56
|
+
file-size-splitter largefile.zip 10M
|
|
57
|
+
|
|
58
|
+
# 出力ディレクトリを指定
|
|
59
|
+
file-size-splitter largefile.zip 10M -o output
|
|
60
|
+
|
|
61
|
+
# バイト数で指定
|
|
62
|
+
file-size-splitter largefile.zip 10485760
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### ファイル復元
|
|
66
|
+
分割時に生成された `restore.bat` または `restore.ps1` を実行します。
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# BATファイルを使用(Windows)
|
|
70
|
+
restore.bat
|
|
71
|
+
|
|
72
|
+
# PS1ファイルを使用(PowerShell)
|
|
73
|
+
powershell -ExecutionPolicy Bypass -File restore.ps1
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## インストール
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install file-size-splitter
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 開発状況
|
|
83
|
+
|
|
84
|
+
- [x] ファイル分割機能の実装
|
|
85
|
+
- [x] BATファイル生成機能の実装
|
|
86
|
+
- [x] PS1ファイル生成機能の実装
|
|
87
|
+
- [x] テストの作成
|
|
88
|
+
- [x] CLIの実装
|
|
89
|
+
- [ ] PyPI公開
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# File Size Splitter
|
|
2
|
+
|
|
3
|
+
ファイルを指定されたサイズで分割し、分割したファイルを復元するツール。
|
|
4
|
+
|
|
5
|
+
## 仕様
|
|
6
|
+
|
|
7
|
+
### 機能1: ファイル分割
|
|
8
|
+
- 指定されたファイルを、指定のサイズで分割する
|
|
9
|
+
- 分割サイズの指定方法:数値のみ(例: `10485760`)または単位付き(例: `10M`, `1G`)の両方に対応
|
|
10
|
+
- 単位: K(キロバイト)、M(メガバイト)、G(ギガバイト)
|
|
11
|
+
- 分割されたファイルには連番を付与する(例: `file.001`, `file.002`, ...)
|
|
12
|
+
- 分割情報を記録したメタデータファイルをJSON形式で生成する
|
|
13
|
+
- 出力先ディレクトリを指定可能(指定なしの場合は入力ファイルと同じディレクトリ)
|
|
14
|
+
- ストリーミング処理でメモリ効率よく分割する(大きなファイルでも対応)
|
|
15
|
+
|
|
16
|
+
### 機能2: 復元用スクリプト生成
|
|
17
|
+
- 分割時にBATファイル(Windows用)とPS1ファイル(PowerShell用)の両方を自動生成
|
|
18
|
+
- 生成されたスクリプトを使用して、分割されたファイルを元のファイルに復元する
|
|
19
|
+
- 復元時のファイル名はメタデータファイルから自動取得
|
|
20
|
+
|
|
21
|
+
## 使用方法
|
|
22
|
+
|
|
23
|
+
### ファイル分割
|
|
24
|
+
```bash
|
|
25
|
+
file-size-splitter <入力ファイル> <分割サイズ> [-o 出力ディレクトリ]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**例:**
|
|
29
|
+
```bash
|
|
30
|
+
# 10MBごとに分割
|
|
31
|
+
file-size-splitter largefile.zip 10M
|
|
32
|
+
|
|
33
|
+
# 出力ディレクトリを指定
|
|
34
|
+
file-size-splitter largefile.zip 10M -o output
|
|
35
|
+
|
|
36
|
+
# バイト数で指定
|
|
37
|
+
file-size-splitter largefile.zip 10485760
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ファイル復元
|
|
41
|
+
分割時に生成された `restore.bat` または `restore.ps1` を実行します。
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# BATファイルを使用(Windows)
|
|
45
|
+
restore.bat
|
|
46
|
+
|
|
47
|
+
# PS1ファイルを使用(PowerShell)
|
|
48
|
+
powershell -ExecutionPolicy Bypass -File restore.ps1
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## インストール
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install file-size-splitter
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 開発状況
|
|
58
|
+
|
|
59
|
+
- [x] ファイル分割機能の実装
|
|
60
|
+
- [x] BATファイル生成機能の実装
|
|
61
|
+
- [x] PS1ファイル生成機能の実装
|
|
62
|
+
- [x] テストの作成
|
|
63
|
+
- [x] CLIの実装
|
|
64
|
+
- [ ] PyPI公開
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "file-size-splitter"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "ファイルを指定されたサイズで分割し、分割したファイルを復元するツール"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "momoandbanana22"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["file", "split", "restore", "batch", "powershell"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Intended Audience :: System Administrators",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.8",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Topic :: System :: Archiving",
|
|
28
|
+
"Topic :: Utilities",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
file-size-splitter = "file_size_splitter.cli:main"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/momoandbanana22/file-size-splitter"
|
|
36
|
+
Repository = "https://github.com/momoandbanana22/file-size-splitter"
|
|
37
|
+
Issues = "https://github.com/momoandbanana22/file-size-splitter/issues"
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
file_size_splitter = ["py.typed"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
python_files = ["test_*.py"]
|
|
48
|
+
python_classes = ["Test*"]
|
|
49
|
+
python_functions = ["test_*"]
|
|
50
|
+
|
|
51
|
+
[tool.black]
|
|
52
|
+
line-length = 100
|
|
53
|
+
target-version = ['py38']
|
|
54
|
+
|
|
55
|
+
[tool.isort]
|
|
56
|
+
profile = "black"
|
|
57
|
+
line_length = 100
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""CLIインターフェース"""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from file_size_splitter.splitter import split_file, generate_bat_script, generate_ps1_script
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main() -> int:
|
|
11
|
+
"""メイン関数"""
|
|
12
|
+
parser = argparse.ArgumentParser(
|
|
13
|
+
description="ファイルを指定されたサイズで分割し、復元用スクリプトを生成する"
|
|
14
|
+
)
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"input_file",
|
|
17
|
+
help="入力ファイルパス"
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"size",
|
|
21
|
+
help="分割サイズ(例: 1024, 1K, 1M, 1G)"
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
"-o", "--output",
|
|
25
|
+
help="出力ディレクトリ(省略時は入力ファイルと同じディレクトリ)"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
args = parser.parse_args()
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
# ファイルを分割
|
|
32
|
+
metadata = split_file(args.input_file, args.size, args.output)
|
|
33
|
+
|
|
34
|
+
# 出力ディレクトリの決定
|
|
35
|
+
if args.output:
|
|
36
|
+
output_dir = Path(args.output)
|
|
37
|
+
else:
|
|
38
|
+
output_dir = Path(args.input_file).parent
|
|
39
|
+
|
|
40
|
+
# BATファイルとPS1ファイルを生成
|
|
41
|
+
bat_path = output_dir / "restore.bat"
|
|
42
|
+
ps1_path = output_dir / "restore.ps1"
|
|
43
|
+
|
|
44
|
+
generate_bat_script(metadata, str(bat_path))
|
|
45
|
+
generate_ps1_script(metadata, str(ps1_path))
|
|
46
|
+
|
|
47
|
+
print(f"分割完了: {metadata['original_file']}")
|
|
48
|
+
print(f" - 分割数: {metadata['part_count']}")
|
|
49
|
+
print(f" - 分割サイズ: {metadata['split_size']} バイト")
|
|
50
|
+
print(f" - 復元スクリプト: restore.bat, restore.ps1")
|
|
51
|
+
|
|
52
|
+
return 0
|
|
53
|
+
|
|
54
|
+
except FileNotFoundError as e:
|
|
55
|
+
print(f"エラー: {e}", file=sys.stderr)
|
|
56
|
+
return 1
|
|
57
|
+
except ValueError as e:
|
|
58
|
+
print(f"エラー: {e}", file=sys.stderr)
|
|
59
|
+
return 1
|
|
60
|
+
except Exception as e:
|
|
61
|
+
print(f"エラー: {e}", file=sys.stderr)
|
|
62
|
+
return 1
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
sys.exit(main())
|
|
File without changes
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""ファイル分割機能"""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def parse_size(size_str: str) -> int:
|
|
9
|
+
"""サイズ文字列をバイト数に変換する
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
size_str: サイズ文字列(例: "1024", "1K", "1M", "1G")
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
バイト数
|
|
16
|
+
|
|
17
|
+
Raises:
|
|
18
|
+
ValueError: 無効なサイズ文字列の場合
|
|
19
|
+
"""
|
|
20
|
+
if not size_str:
|
|
21
|
+
raise ValueError("サイズ文字列が空です")
|
|
22
|
+
|
|
23
|
+
size_str = size_str.strip().upper()
|
|
24
|
+
|
|
25
|
+
# 単位のチェック
|
|
26
|
+
units = {
|
|
27
|
+
'K': 1024,
|
|
28
|
+
'M': 1024 * 1024,
|
|
29
|
+
'G': 1024 * 1024 * 1024,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for unit, multiplier in units.items():
|
|
33
|
+
if size_str.endswith(unit):
|
|
34
|
+
try:
|
|
35
|
+
num = float(size_str[:-1])
|
|
36
|
+
return int(num * multiplier)
|
|
37
|
+
except ValueError:
|
|
38
|
+
raise ValueError(f"無効なサイズ指定: {size_str}")
|
|
39
|
+
|
|
40
|
+
# 単位なし(バイト)
|
|
41
|
+
try:
|
|
42
|
+
return int(size_str)
|
|
43
|
+
except ValueError:
|
|
44
|
+
raise ValueError(f"無効なサイズ指定: {size_str}")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def split_file(input_file: str, size_str: str, output_dir: str = None) -> Dict[str, Any]:
|
|
48
|
+
"""ファイルを指定されたサイズで分割する
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
input_file: 入力ファイルパス
|
|
52
|
+
size_str: 分割サイズ(例: "1024", "1K", "1M")
|
|
53
|
+
output_dir: 出力ディレクトリ(省略時は入力ファイルと同じディレクトリ)
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
メタデータ辞書
|
|
57
|
+
"""
|
|
58
|
+
input_path = Path(input_file)
|
|
59
|
+
if not input_path.exists():
|
|
60
|
+
raise FileNotFoundError(f"ファイルが見つかりません: {input_file}")
|
|
61
|
+
|
|
62
|
+
# 分割サイズをパース
|
|
63
|
+
split_size = parse_size(size_str)
|
|
64
|
+
|
|
65
|
+
# 出力ディレクトリの決定
|
|
66
|
+
if output_dir is None:
|
|
67
|
+
output_path = input_path.parent
|
|
68
|
+
else:
|
|
69
|
+
output_path = Path(output_dir)
|
|
70
|
+
output_path.mkdir(parents=True, exist_ok=True)
|
|
71
|
+
|
|
72
|
+
# メタデータの初期化
|
|
73
|
+
metadata: Dict[str, Any] = {
|
|
74
|
+
"original_file": input_path.name,
|
|
75
|
+
"original_size": input_path.stat().st_size,
|
|
76
|
+
"split_size": split_size,
|
|
77
|
+
"part_count": 0,
|
|
78
|
+
"parts": [],
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# ストリーミングでファイルを分割
|
|
82
|
+
part_number = 1
|
|
83
|
+
with open(input_path, "rb") as f:
|
|
84
|
+
while True:
|
|
85
|
+
chunk = f.read(split_size)
|
|
86
|
+
if not chunk:
|
|
87
|
+
break
|
|
88
|
+
|
|
89
|
+
# 分割ファイルのパス
|
|
90
|
+
part_filename = f"{input_path.name}.{part_number:03d}"
|
|
91
|
+
part_path = output_path / part_filename
|
|
92
|
+
|
|
93
|
+
# 分割ファイルを書き込み
|
|
94
|
+
with open(part_path, "wb") as part_f:
|
|
95
|
+
part_f.write(chunk)
|
|
96
|
+
|
|
97
|
+
# メタデータに追加
|
|
98
|
+
metadata["parts"].append({
|
|
99
|
+
"filename": part_filename,
|
|
100
|
+
"size": len(chunk),
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
part_number += 1
|
|
104
|
+
|
|
105
|
+
metadata["part_count"] = part_number - 1
|
|
106
|
+
|
|
107
|
+
# メタデータファイルを保存
|
|
108
|
+
metadata_path = output_path / f"{input_path.name}.metadata.json"
|
|
109
|
+
with open(metadata_path, "w", encoding="utf-8") as f:
|
|
110
|
+
json.dump(metadata, f, indent=2, ensure_ascii=False)
|
|
111
|
+
|
|
112
|
+
return metadata
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def generate_bat_script(metadata: Dict[str, Any], output_path: str) -> None:
|
|
116
|
+
"""復元用BATファイルを生成する
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
metadata: メタデータ辞書
|
|
120
|
+
output_path: 出力ファイルパス
|
|
121
|
+
"""
|
|
122
|
+
original_file = metadata["original_file"]
|
|
123
|
+
parts = metadata["parts"]
|
|
124
|
+
|
|
125
|
+
# BATファイルの内容を生成
|
|
126
|
+
lines = [
|
|
127
|
+
"@echo off",
|
|
128
|
+
"chcp 65001 > nul",
|
|
129
|
+
f"echo 復元中: {original_file}",
|
|
130
|
+
"",
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
# copyコマンドでファイルを結合
|
|
134
|
+
part_files = " + ".join([f'"{p["filename"]}"' for p in parts])
|
|
135
|
+
lines.append(f"copy /B {part_files} \"{original_file}\"")
|
|
136
|
+
lines.append("")
|
|
137
|
+
lines.append(f"echo 復元完了: {original_file}")
|
|
138
|
+
lines.append("pause")
|
|
139
|
+
|
|
140
|
+
# BATファイルを書き込み
|
|
141
|
+
bat_content = "\r\n".join(lines)
|
|
142
|
+
with open(output_path, "w", encoding="shift-jis") as f:
|
|
143
|
+
f.write(bat_content)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def generate_ps1_script(metadata: Dict[str, Any], output_path: str) -> None:
|
|
147
|
+
"""復元用PS1ファイルを生成する
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
metadata: メタデータ辞書
|
|
151
|
+
output_path: 出力ファイルパス
|
|
152
|
+
"""
|
|
153
|
+
original_file = metadata["original_file"]
|
|
154
|
+
parts = metadata["parts"]
|
|
155
|
+
|
|
156
|
+
# PS1ファイルの内容を生成
|
|
157
|
+
lines = [
|
|
158
|
+
"# 復元用スクリプト",
|
|
159
|
+
f"Write-Host '復元中: {original_file}'",
|
|
160
|
+
"",
|
|
161
|
+
]
|
|
162
|
+
|
|
163
|
+
# Get-ContentとSet-Contentでファイルを結合
|
|
164
|
+
part_files = [f'"{p["filename"]}"' for p in parts]
|
|
165
|
+
lines.append(f"$parts = {', '.join(part_files)}")
|
|
166
|
+
lines.append("$output = \"" + original_file + "\"")
|
|
167
|
+
lines.append("")
|
|
168
|
+
lines.append("$parts | ForEach-Object { Get-Content -Path $_ -Raw } | Set-Content -Path $output")
|
|
169
|
+
lines.append("")
|
|
170
|
+
lines.append(f"Write-Host '復元完了: {original_file}'")
|
|
171
|
+
lines.append("Read-Host 'Enterキーを押してください'")
|
|
172
|
+
|
|
173
|
+
# PS1ファイルを書き込み
|
|
174
|
+
ps1_content = "\r\n".join(lines)
|
|
175
|
+
with open(output_path, "w", encoding="utf-8") as f:
|
|
176
|
+
f.write(ps1_content)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: file-size-splitter
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ファイルを指定されたサイズで分割し、分割したファイルを復元するツール
|
|
5
|
+
Author: momoandbanana22
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/momoandbanana22/file-size-splitter
|
|
8
|
+
Project-URL: Repository, https://github.com/momoandbanana22/file-size-splitter
|
|
9
|
+
Project-URL: Issues, https://github.com/momoandbanana22/file-size-splitter/issues
|
|
10
|
+
Keywords: file,split,restore,batch,powershell
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: System :: Archiving
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# File Size Splitter
|
|
27
|
+
|
|
28
|
+
ファイルを指定されたサイズで分割し、分割したファイルを復元するツール。
|
|
29
|
+
|
|
30
|
+
## 仕様
|
|
31
|
+
|
|
32
|
+
### 機能1: ファイル分割
|
|
33
|
+
- 指定されたファイルを、指定のサイズで分割する
|
|
34
|
+
- 分割サイズの指定方法:数値のみ(例: `10485760`)または単位付き(例: `10M`, `1G`)の両方に対応
|
|
35
|
+
- 単位: K(キロバイト)、M(メガバイト)、G(ギガバイト)
|
|
36
|
+
- 分割されたファイルには連番を付与する(例: `file.001`, `file.002`, ...)
|
|
37
|
+
- 分割情報を記録したメタデータファイルをJSON形式で生成する
|
|
38
|
+
- 出力先ディレクトリを指定可能(指定なしの場合は入力ファイルと同じディレクトリ)
|
|
39
|
+
- ストリーミング処理でメモリ効率よく分割する(大きなファイルでも対応)
|
|
40
|
+
|
|
41
|
+
### 機能2: 復元用スクリプト生成
|
|
42
|
+
- 分割時にBATファイル(Windows用)とPS1ファイル(PowerShell用)の両方を自動生成
|
|
43
|
+
- 生成されたスクリプトを使用して、分割されたファイルを元のファイルに復元する
|
|
44
|
+
- 復元時のファイル名はメタデータファイルから自動取得
|
|
45
|
+
|
|
46
|
+
## 使用方法
|
|
47
|
+
|
|
48
|
+
### ファイル分割
|
|
49
|
+
```bash
|
|
50
|
+
file-size-splitter <入力ファイル> <分割サイズ> [-o 出力ディレクトリ]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**例:**
|
|
54
|
+
```bash
|
|
55
|
+
# 10MBごとに分割
|
|
56
|
+
file-size-splitter largefile.zip 10M
|
|
57
|
+
|
|
58
|
+
# 出力ディレクトリを指定
|
|
59
|
+
file-size-splitter largefile.zip 10M -o output
|
|
60
|
+
|
|
61
|
+
# バイト数で指定
|
|
62
|
+
file-size-splitter largefile.zip 10485760
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### ファイル復元
|
|
66
|
+
分割時に生成された `restore.bat` または `restore.ps1` を実行します。
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# BATファイルを使用(Windows)
|
|
70
|
+
restore.bat
|
|
71
|
+
|
|
72
|
+
# PS1ファイルを使用(PowerShell)
|
|
73
|
+
powershell -ExecutionPolicy Bypass -File restore.ps1
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## インストール
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install file-size-splitter
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 開発状況
|
|
83
|
+
|
|
84
|
+
- [x] ファイル分割機能の実装
|
|
85
|
+
- [x] BATファイル生成機能の実装
|
|
86
|
+
- [x] PS1ファイル生成機能の実装
|
|
87
|
+
- [x] テストの作成
|
|
88
|
+
- [x] CLIの実装
|
|
89
|
+
- [ ] PyPI公開
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/file_size_splitter/__init__.py
|
|
4
|
+
src/file_size_splitter/cli.py
|
|
5
|
+
src/file_size_splitter/py.typed
|
|
6
|
+
src/file_size_splitter/splitter.py
|
|
7
|
+
src/file_size_splitter.egg-info/PKG-INFO
|
|
8
|
+
src/file_size_splitter.egg-info/SOURCES.txt
|
|
9
|
+
src/file_size_splitter.egg-info/dependency_links.txt
|
|
10
|
+
src/file_size_splitter.egg-info/entry_points.txt
|
|
11
|
+
src/file_size_splitter.egg-info/top_level.txt
|
|
12
|
+
tests/test_splitter.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
file_size_splitter
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""ファイル分割機能のテスト"""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_parse_size_bytes():
|
|
8
|
+
"""数値のみ(バイト)のパース"""
|
|
9
|
+
from file_size_splitter.splitter import parse_size
|
|
10
|
+
|
|
11
|
+
assert parse_size("1024") == 1024
|
|
12
|
+
assert parse_size("100") == 100
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_parse_size_with_unit():
|
|
16
|
+
"""単位付きのパース"""
|
|
17
|
+
from file_size_splitter.splitter import parse_size
|
|
18
|
+
|
|
19
|
+
assert parse_size("1K") == 1024
|
|
20
|
+
assert parse_size("1M") == 1024 * 1024
|
|
21
|
+
assert parse_size("1G") == 1024 * 1024 * 1024
|
|
22
|
+
assert parse_size("10K") == 10 * 1024
|
|
23
|
+
assert parse_size("5M") == 5 * 1024 * 1024
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_parse_size_invalid():
|
|
27
|
+
"""無効なサイズ指定"""
|
|
28
|
+
from file_size_splitter.splitter import parse_size
|
|
29
|
+
|
|
30
|
+
with pytest.raises(ValueError):
|
|
31
|
+
parse_size("invalid")
|
|
32
|
+
|
|
33
|
+
with pytest.raises(ValueError):
|
|
34
|
+
parse_size("")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_split_file(tmp_path):
|
|
38
|
+
"""ファイル分割機能"""
|
|
39
|
+
from file_size_splitter.splitter import split_file
|
|
40
|
+
|
|
41
|
+
# テスト用ファイルを作成
|
|
42
|
+
test_file = tmp_path / "test.txt"
|
|
43
|
+
test_content = b"a" * 100 # 100バイト
|
|
44
|
+
test_file.write_bytes(test_content)
|
|
45
|
+
|
|
46
|
+
# 50バイトごとに分割
|
|
47
|
+
output_dir = tmp_path / "output"
|
|
48
|
+
metadata = split_file(str(test_file), "50", str(output_dir))
|
|
49
|
+
|
|
50
|
+
# 分割ファイルが2つ作成されていることを確認
|
|
51
|
+
assert (output_dir / "test.txt.001").exists()
|
|
52
|
+
assert (output_dir / "test.txt.002").exists()
|
|
53
|
+
|
|
54
|
+
# メタデータが生成されていることを確認
|
|
55
|
+
assert metadata["original_file"] == "test.txt"
|
|
56
|
+
assert metadata["original_size"] == 100
|
|
57
|
+
assert metadata["split_size"] == 50
|
|
58
|
+
assert metadata["part_count"] == 2
|
|
59
|
+
assert len(metadata["parts"]) == 2
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_generate_bat_script(tmp_path):
|
|
63
|
+
"""BATファイル生成機能"""
|
|
64
|
+
from file_size_splitter.splitter import generate_bat_script
|
|
65
|
+
|
|
66
|
+
metadata = {
|
|
67
|
+
"original_file": "test.txt",
|
|
68
|
+
"original_size": 100,
|
|
69
|
+
"split_size": 50,
|
|
70
|
+
"part_count": 2,
|
|
71
|
+
"parts": [
|
|
72
|
+
{"filename": "test.txt.001", "size": 50},
|
|
73
|
+
{"filename": "test.txt.002", "size": 50},
|
|
74
|
+
],
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
bat_path = tmp_path / "restore.bat"
|
|
78
|
+
generate_bat_script(metadata, str(bat_path))
|
|
79
|
+
|
|
80
|
+
# BATファイルが生成されていることを確認
|
|
81
|
+
assert bat_path.exists()
|
|
82
|
+
|
|
83
|
+
# BATファイルの内容を確認
|
|
84
|
+
bat_content = bat_path.read_text(encoding="shift-jis")
|
|
85
|
+
assert "@echo off" in bat_content
|
|
86
|
+
assert "test.txt.001" in bat_content
|
|
87
|
+
assert "test.txt.002" in bat_content
|
|
88
|
+
assert "copy" in bat_content
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_generate_ps1_script(tmp_path):
|
|
92
|
+
"""PS1ファイル生成機能"""
|
|
93
|
+
from file_size_splitter.splitter import generate_ps1_script
|
|
94
|
+
|
|
95
|
+
metadata = {
|
|
96
|
+
"original_file": "test.txt",
|
|
97
|
+
"original_size": 100,
|
|
98
|
+
"split_size": 50,
|
|
99
|
+
"part_count": 2,
|
|
100
|
+
"parts": [
|
|
101
|
+
{"filename": "test.txt.001", "size": 50},
|
|
102
|
+
{"filename": "test.txt.002", "size": 50},
|
|
103
|
+
],
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
ps1_path = tmp_path / "restore.ps1"
|
|
107
|
+
generate_ps1_script(metadata, str(ps1_path))
|
|
108
|
+
|
|
109
|
+
# PS1ファイルが生成されていることを確認
|
|
110
|
+
assert ps1_path.exists()
|
|
111
|
+
|
|
112
|
+
# PS1ファイルの内容を確認
|
|
113
|
+
ps1_content = ps1_path.read_text(encoding="utf-8")
|
|
114
|
+
assert "Write-Host" in ps1_content
|
|
115
|
+
assert "test.txt.001" in ps1_content
|
|
116
|
+
assert "test.txt.002" in ps1_content
|
|
117
|
+
assert "Get-Content" in ps1_content
|