read-write-edit-tools 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,1333 @@
1
+ Metadata-Version: 2.4
2
+ Name: read-write-edit-tools
3
+ Version: 0.1.0
4
+ Summary: Fast hex-line-numbered file read, write, and edit CLI
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/llaa33219/read-write-edit-tools
7
+ Project-URL: Repository, https://github.com/llaa33219/read-write-edit-tools
8
+ Project-URL: Issues, https://github.com/llaa33219/read-write-edit-tools/issues
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # read-write-edit-tools (`rwe`)
15
+
16
+ `read-write-edit-tools` is a small, fast command-line tool for reading,
17
+ creating, and editing UTF-8 text files. It is written in Python, uses only the
18
+ Python standard library at runtime, and installs two equivalent commands:
19
+
20
+ ```sh
21
+ rwe
22
+ read-write-edit-tools
23
+ ```
24
+
25
+ Examples below use the shorter `rwe` name. Replace it with
26
+ `read-write-edit-tools` anywhere if you prefer the long name. The **PyPI
27
+ distribution name is `read-write-edit-tools`**, available at
28
+ <https://pypi.org/project/read-write-edit-tools/> after the first automated
29
+ release.
30
+
31
+ The tool deliberately has a narrow scope:
32
+
33
+ - `read` displays text with stable, 1-based hexadecimal line addresses.
34
+ - `write` creates a new file and **refuses to overwrite anything that already
35
+ exists**.
36
+ - `edit` replaces one or more lines, including multiple lines in one block,
37
+ using addresses from the **original file**.
38
+
39
+ It is not a general-purpose editor, binary-file tool, search tool, merge tool,
40
+ or interactive terminal UI. It does not delete lines or files, append to
41
+ files, create parent directories, or provide pattern-based substitution.
42
+
43
+ > **The essential `edit` rule:** every address in one `edit` command refers to
44
+ > the file as it existed **before that command started**. If one replacement
45
+ > adds or removes lines, that does not change any other address in the same
46
+ > command. The complete example below shows this explicitly.
47
+
48
+ ## Contents
49
+
50
+ 1. [Requirements and installation](#requirements-and-installation)
51
+ 2. [Command reference at a glance](#command-reference-at-a-glance)
52
+ 3. [Line addresses and shell conventions](#line-addresses-and-shell-conventions)
53
+ 4. [Complete workflow](#complete-workflow)
54
+ 5. [`read`: display numbered content](#read-display-numbered-content)
55
+ 6. [`write`: create a new file only](#write-create-a-new-file-only)
56
+ 7. [`edit`: replace original lines](#edit-replace-original-lines)
57
+ 8. [Input, output, paths, and encoding](#input-output-paths-and-encoding)
58
+ 9. [Safety, preservation, and limitations](#safety-preservation-and-limitations)
59
+ 10. [Errors, exit codes, and troubleshooting](#errors-exit-codes-and-troubleshooting)
60
+ 11. [Development and project layout](#development-and-project-layout)
61
+ 12. [License](#license)
62
+
63
+ ## Requirements and installation
64
+
65
+ ### Requirements
66
+
67
+ - Python **3.9 or newer**
68
+ - **[uv](https://docs.astral.sh/uv/) is recommended** for installing and
69
+ running the CLI in an isolated environment
70
+ - `pip` is supported as an alternative
71
+ - A UTF-8 locale is recommended so filenames and terminal messages display
72
+ correctly
73
+ - No third-party Python runtime dependencies
74
+
75
+ The package has been tested on Linux with Python 3.14. The code uses standard
76
+ Python APIs, but other Python versions and operating systems have not been
77
+ verified as part of that test run.
78
+
79
+ ### Recommended: install from PyPI with `uv tool install`
80
+
81
+ Install the published `read-write-edit-tools` distribution as a persistent,
82
+ user-level command-line tool:
83
+
84
+ ```sh
85
+ uv tool install read-write-edit-tools
86
+ ```
87
+
88
+ `uv tool install` creates an isolated environment for this package and exposes
89
+ its commands in uv's tool executable directory. It does not install the
90
+ package into your current project's virtual environment, and it does not
91
+ require `pip` in that environment.
92
+
93
+ After installation, both names are available:
94
+
95
+ ```sh
96
+ rwe --help
97
+ read-write-edit-tools --help
98
+ ```
99
+
100
+ Both print the package version with `--version`:
101
+
102
+ ```sh
103
+ rwe --version
104
+ read-write-edit-tools --version
105
+ ```
106
+
107
+ If your shell cannot find `rwe`, follow uv's PATH instructions or run:
108
+
109
+ ```sh
110
+ uv tool update-shell
111
+ ```
112
+
113
+ Then start a new shell or reload its configuration as instructed by uv. You
114
+ can inspect the installed tool with:
115
+
116
+ ```sh
117
+ uv tool list
118
+ ```
119
+
120
+ #### Upgrade or remove a uv tool installation
121
+
122
+ Upgrade to the latest published version:
123
+
124
+ ```sh
125
+ uv tool upgrade read-write-edit-tools
126
+ ```
127
+
128
+ Remove the persistent tool and its command links:
129
+
130
+ ```sh
131
+ uv tool uninstall read-write-edit-tools
132
+ ```
133
+
134
+ These commands manage the installed CLI environment, not files you created or
135
+ edited with `rwe`.
136
+
137
+ ### Ephemeral PyPI use with `uvx`: no persistent tool installation
138
+
139
+ `uvx` is uv's tool-running interface. It creates an ephemeral tool environment
140
+ and does not add `rwe` to your persistent installed-tool commands. By default,
141
+ uv keeps that environment in its cache for fast reuse; `uvx` does not
142
+ necessarily create and delete a fresh environment for every invocation.
143
+
144
+ Run the `rwe` command supplied by the full `read-write-edit-tools` PyPI
145
+ package:
146
+
147
+ ```sh
148
+ uvx --from read-write-edit-tools rwe --help
149
+ uvx --from read-write-edit-tools rwe read notes.txt
150
+ ```
151
+
152
+ The explicit `--from read-write-edit-tools` is important: it names the PyPI
153
+ distribution, while `rwe` is the executable provided by that distribution.
154
+ The long executable name works too:
155
+
156
+ ```sh
157
+ uvx --from read-write-edit-tools read-write-edit-tools --version
158
+ ```
159
+
160
+ “Ephemeral” describes the **CLI installation environment**, not the files on
161
+ which the command operates. `read` only reads, but `write` and `edit` still
162
+ create or modify their target files exactly as documented:
163
+
164
+ ```sh
165
+ uvx --from read-write-edit-tools rwe write ephemeral-demo.txt 'First line
166
+ Second line'
167
+
168
+ uvx --from read-write-edit-tools rwe edit ephemeral-demo.txt '01: Replacement for original line 01
169
+ An additional line
170
+ 02: Replacement for original line 02'
171
+
172
+ uvx --from read-write-edit-tools rwe read ephemeral-demo.txt
173
+ ```
174
+
175
+ The resulting `ephemeral-demo.txt` remains on disk after `uvx` exits. By
176
+ default, uv may cache downloaded packages and execution environments to make
177
+ later invocations faster. `uvx` therefore does not promise to erase every
178
+ cached byte immediately or avoid network access on an uncached first run.
179
+
180
+ For a fresh temporary cache for one invocation, use:
181
+
182
+ ```sh
183
+ uvx --no-cache --from read-write-edit-tools rwe --version
184
+ ```
185
+
186
+ To refresh cached package information when needed:
187
+
188
+ ```sh
189
+ uvx --refresh --from read-write-edit-tools rwe --version
190
+ ```
191
+
192
+ ### Alternative: install from PyPI with `pip`
193
+
194
+ ```sh
195
+ python3 -m pip install read-write-edit-tools
196
+ ```
197
+
198
+ Remove that installation using the same Python environment:
199
+
200
+ ```sh
201
+ python3 -m pip uninstall read-write-edit-tools
202
+ ```
203
+
204
+ ### Install a local checkout for development
205
+
206
+ For a checkout that is not yet published, or to test local changes, run these
207
+ commands from the directory containing `pyproject.toml`:
208
+
209
+ ```sh
210
+ uv tool install .
211
+ uv tool install --reinstall . # Reinstall after changing the checkout
212
+ ```
213
+
214
+ Use the local package with `uvx` by changing the `--from` source to `.`:
215
+
216
+ ```sh
217
+ uvx --from . rwe --help
218
+ uvx --from . rwe read README.md 01:0a
219
+ ```
220
+
221
+ A pip virtual environment is another development option:
222
+
223
+ ```sh
224
+ python3 -m venv .venv
225
+ .venv/bin/python -m pip install .
226
+ .venv/bin/rwe --help
227
+ ```
228
+
229
+ ### Run from Python source without building or installing a tool
230
+
231
+ From the source checkout:
232
+
233
+ ```sh
234
+ PYTHONPATH=src python3 -m rwe --help
235
+ PYTHONPATH=src python3 -m rwe read README.md 01:0a
236
+ ```
237
+
238
+ This bypasses both `uv tool install` and `uvx` and is mainly useful during
239
+ development.
240
+
241
+ ## Command reference at a glance
242
+
243
+ ```text
244
+ rwe read FILE [RANGE]
245
+ rwe write FILE CONTENT
246
+ rwe edit FILE EDITS
247
+ ```
248
+
249
+ | Command | Purpose | Modifies a file? |
250
+ |---|---|---|
251
+ | `rwe read FILE` | Print up to 1000 lines with hexadecimal addresses | No |
252
+ | `rwe read FILE RANGE` | Print a single line or inclusive range | No |
253
+ | `rwe write FILE CONTENT` | Create a file containing exactly `CONTENT` | Yes, only if `FILE` does not exist |
254
+ | `rwe edit FILE EDITS` | Replace addressed lines from the original file | Yes |
255
+ | `rwe --help` or `rwe -h` | Print a short command reference | No |
256
+ | `rwe --version` or `rwe -V` | Print the version | No |
257
+
258
+ `read`, `write`, and `edit` also accept `--help` or `-h` as their only operand.
259
+
260
+ ### Arguments
261
+
262
+ | Argument | Meaning |
263
+ |---|---|
264
+ | `FILE` | Path to the file to read, create, or edit |
265
+ | `RANGE` | One hexadecimal address, or `START:END`; see below |
266
+ | `CONTENT` | The complete new file content as **one shell argument** |
267
+ | `EDITS` | One or more edit blocks as **one shell argument** |
268
+
269
+ For `write` and `edit`, a final argument of exactly `-` reads `CONTENT` or
270
+ `EDITS` from standard input. `read FILE -` is **not** standard-input syntax;
271
+ for `read`, `-` is interpreted as a range and is invalid.
272
+
273
+ ### Quick examples
274
+
275
+ ```sh
276
+ # Create a multiline file. Use quotes so this is one CONTENT argument.
277
+ rwe write notes.txt 'First line
278
+ Second line
279
+ Third line'
280
+
281
+ # Read the whole file, subject to the 1000-line limit.
282
+ rwe read notes.txt
283
+
284
+ # Read only original line 03, or an inclusive range.
285
+ rwe read notes.txt 03
286
+ rwe read notes.txt 01:03
287
+
288
+ # Replace original lines 01 and 03 in one operation.
289
+ rwe edit notes.txt '01: New first line
290
+ 03: New third line'
291
+
292
+ # Replace original line 02 with two lines.
293
+ rwe edit notes.txt '02: Replacement line
294
+ An additional line'
295
+
296
+ # Re-read after every edit to obtain the new addresses.
297
+ rwe read notes.txt
298
+ ```
299
+
300
+ ## Line addresses and shell conventions
301
+
302
+ ### Hexadecimal, 1-based addresses
303
+
304
+ Addresses are hexadecimal (`0`–`9`, `a`–`f`), and the first line is `01`, not
305
+ `00` or decimal `1` interpreted in base ten. These examples are equivalent:
306
+
307
+ | Hexadecimal address | Decimal line number |
308
+ |---|---|
309
+ | `01` | 1 |
310
+ | `09` | 9 |
311
+ | `0a` | 10 |
312
+ | `10` | 16 |
313
+ | `64` | 100 |
314
+ | `ff` | 255 |
315
+ | `100` | 256 |
316
+ | `3e8` | 1000 |
317
+ | `b7` | 183 |
318
+
319
+ Output uses lowercase hexadecimal. Input accepts lowercase or uppercase, so
320
+ `b7` and `B7` refer to the same line. Leading zeros are allowed on input:
321
+ `1`, `01`, and `001` all address line 1. In one `edit` argument, using more
322
+ than one spelling of the same address is a duplicate-address error.
323
+
324
+ `00` is always invalid, including `000` and other all-zero forms.
325
+
326
+ ### Address width
327
+
328
+ The displayed address width depends on the **total number of lines in the
329
+ file**, not on the number of lines selected for output.
330
+
331
+ | Total file lines | Width | First address | Example last address |
332
+ |---|---|---|---|
333
+ | 1 through 255 (`ff`) | 2 digits | `01` | `ff` at 255 lines |
334
+ | 256 through 4095 (`fff`) | 3 digits | `001` | `fff` at 4095 lines |
335
+ | 4096 through 65535 (`ffff`) | 4 digits | `0001` | `ffff` at 65535 lines |
336
+
337
+ The same rule continues for larger files. For example:
338
+
339
+ - A 3-line file uses `01`, `02`, `03`.
340
+ - A 256-line file uses `001` through `100`.
341
+ - A 4096-line file uses `0001` through `1000`.
342
+ - Reading only line 1 of a 500-line file prints `001: ...`, not `01: ...`.
343
+
344
+ ### Shell quoting and multiline arguments
345
+
346
+ The shell, not `rwe`, handles quotes. Use single quotes around multiline
347
+ content when the content itself contains no single quote:
348
+
349
+ ```sh
350
+ rwe write poem.txt 'Line one
351
+ Line two'
352
+ ```
353
+
354
+ The opening quote can be at the end of one terminal line and the closing quote
355
+ several lines later. The newlines between them are part of the argument.
356
+
357
+ Within POSIX-style single quotes:
358
+
359
+ - `\n` is two characters (backslash and `n`), **not** a newline.
360
+ - `$HOME`, backticks, and `*` remain literal; the shell does not expand them.
361
+ - A literal single quote cannot be embedded directly inside single quotes.
362
+
363
+ For content containing shell-sensitive text or many quotes, standard input is
364
+ usually clearer:
365
+
366
+ ```sh
367
+ rwe write literal.txt - <<'EOF'
368
+ A literal $HOME, a backslash-n: \n, and 'single quotes'.
369
+ EOF
370
+ ```
371
+
372
+ The quoted `<<'EOF'` prevents shell expansion in the here-document. The final
373
+ newline supplied by the here-document is part of the file content.
374
+
375
+ ### Filenames beginning with `-`
376
+
377
+ Put `--` immediately after the subcommand:
378
+
379
+ ```sh
380
+ rwe read -- -notes.txt
381
+ rwe write -- -new.txt 'content'
382
+ rwe edit -- -notes.txt '01: replacement'
383
+ ```
384
+
385
+ Paths containing spaces follow normal shell quoting rules:
386
+
387
+ ```sh
388
+ rwe read 'my notes.txt'
389
+ ```
390
+
391
+ ## Complete workflow
392
+
393
+ This example demonstrates the most easily misunderstood behavior: original
394
+ addresses remain fixed throughout one `edit`, even when a replacement expands
395
+ to multiple lines.
396
+
397
+ ### 1. Create the original file
398
+
399
+ ```sh
400
+ rwe write example.txt 'First line
401
+ Second line
402
+ Third line'
403
+ ```
404
+
405
+ ### 2. Read it before editing
406
+
407
+ ```sh
408
+ rwe read example.txt
409
+ ```
410
+
411
+ Output:
412
+
413
+ ```text
414
+ 01: First line
415
+ 02: Second line
416
+ 03: Third line
417
+ ```
418
+
419
+ ### 3. Expand line 01 and replace line 03 in the same command
420
+
421
+ ```sh
422
+ rwe edit example.txt '01: New first line
423
+ Inserted second line
424
+ 03: New third line'
425
+ ```
426
+
427
+ The edit argument has two blocks:
428
+
429
+ 1. Replace **original line `01`** with two lines: `New first line` and
430
+ `Inserted second line`.
431
+ 2. Replace **original line `03`** (`Third line`) with `New third line`.
432
+
433
+ ### 4. Read the result
434
+
435
+ ```text
436
+ 01: New first line
437
+ 02: Inserted second line
438
+ 03: Second line
439
+ 04: New third line
440
+ ```
441
+
442
+ Address `03` in the command did **not** mean “line 3 after inserting a line.”
443
+ It still meant original `Third line`. Original `Second line` was not edited,
444
+ so it moved from line `02` to line `03` in the result. The replacement for
445
+ original line `03` consequently appears at line `04`.
446
+
447
+ Internally, `rwe` validates all addresses against the original file and applies
448
+ replacements from bottom to top. The practical consequences are:
449
+
450
+ - Every address in one call uses the same original snapshot.
451
+ - Blocks may be written in ascending, descending, or mixed address order.
452
+ - A replacement with multiple lines never shifts later addresses in that
453
+ same call.
454
+ - You cannot address a newly inserted line elsewhere in the same call.
455
+ - Addresses are not persistent IDs. After the command finishes, run `read`
456
+ again and use its addresses for the next `edit`.
457
+
458
+ For example, the following two-block edit is also valid and has the same
459
+ addressing semantics:
460
+
461
+ ```sh
462
+ rwe edit example.txt '04: Replacement for current original line 04
463
+ 01: Replacement for current original line 01'
464
+ ```
465
+
466
+ Here `04` and `01` refer to the result shown immediately above, because this
467
+ is a new invocation with a new original snapshot.
468
+
469
+ ## `read`: display numbered content
470
+
471
+ ### Read the beginning of a file
472
+
473
+ ```sh
474
+ rwe read notes.txt
475
+ ```
476
+
477
+ Each selected line is printed as:
478
+
479
+ ```text
480
+ ADDRESS: CONTENT
481
+ ```
482
+
483
+ There is one space after the colon, inserted by the output formatter. It is
484
+ not part of the original file content. Content itself is printed without its
485
+ line terminator, followed by the output newline.
486
+
487
+ Example:
488
+
489
+ ```text
490
+ 01: First line
491
+ 02: Second line
492
+ 03: Third line
493
+ ```
494
+
495
+ A blank source line appears as an address, colon, and one space:
496
+
497
+ ```text
498
+ 01: Non-empty line
499
+ 02:
500
+ 03: Another non-empty line
501
+ ```
502
+
503
+ `read` does not modify the file. An empty file produces no output and exits
504
+ successfully. A file containing one empty line produces `01: `.
505
+
506
+ ### Select one line
507
+
508
+ ```sh
509
+ rwe read notes.txt b7
510
+ ```
511
+
512
+ This prints only line `b7` (decimal 183), with its address.
513
+
514
+ ### Select an inclusive range
515
+
516
+ ```sh
517
+ rwe read notes.txt 01:64
518
+ ```
519
+
520
+ This prints lines `01` through `64`, including both endpoints.
521
+
522
+ | Range | Meaning |
523
+ |---|---|
524
+ | `b7` | Only line `b7` |
525
+ | `01:64` | `01` through `64`, inclusive |
526
+ | `01:` | `01` through end of file, subject to the output limit |
527
+ | `:64` | Beginning through `64`, subject to the output limit |
528
+ | `:` | Equivalent to `01:`; the entire file, subject to the output limit |
529
+
530
+ A range may run past the end of the file as long as its **start exists**. For
531
+ example, `02:ff` on a three-line file prints lines `02` and `03`. It does not
532
+ create placeholder lines.
533
+
534
+ These are errors:
535
+
536
+ - A start address beyond end of file, including any range on an empty file
537
+ - A reversed range such as `03:01`
538
+ - A non-hexadecimal address such as `xyz`
539
+ - Zero as an address
540
+ - More than one range colon, such as `01:02:03`
541
+
542
+ ### The 1000-line output limit
543
+
544
+ Every invocation prints at most **1000 content lines**, even if the selected
545
+ range contains more. This applies equally to a full read, a single open-ended
546
+ range, and a finite range.
547
+
548
+ 1000 decimal is `3e8` hexadecimal. Therefore, on a file with more than 1000
549
+ lines:
550
+
551
+ ```sh
552
+ rwe read large.txt
553
+ ```
554
+
555
+ prints addresses `001: ...` through `3e8: ...` (three digits because the file
556
+ has more than 255 lines), and writes this notice to standard error:
557
+
558
+ ```text
559
+ rwe: showing at most 1000 lines; continue at line 3e9
560
+ ```
561
+
562
+ Continue with:
563
+
564
+ ```sh
565
+ rwe read large.txt 3e9:
566
+ ```
567
+
568
+ For a range beginning elsewhere, the continuation address is the range start
569
+ plus 1000. For example, `rwe read large.txt 02:` starts at `002`; after 1000
570
+ lines the continuation notice names `3ea`.
571
+
572
+ If a finite range contains exactly 1000 lines, no continuation notice is
573
+ printed. If it contains more than 1000 lines, the notice is printed even if
574
+ the file ends immediately after the omitted part of that range.
575
+
576
+ The limit controls output only. It does not truncate or modify the file. `rwe`
577
+ still counts the remainder to choose the correct address width, using binary
578
+ chunks rather than formatting every unselected line.
579
+
580
+ ### Read behavior summary
581
+
582
+ | Situation | Behavior |
583
+ |---|---|
584
+ | Empty file, no range | Success, no output |
585
+ | Empty file, explicit range | Error: start is outside the file |
586
+ | Range start exists, end is beyond EOF | Print through EOF |
587
+ | Selected line has invalid UTF-8 | Error, no numbered content emitted |
588
+ | More than 1000 selected lines | Print first 1000 and a continuation notice on stderr |
589
+ | CRLF input | Display content without the CRLF terminator |
590
+ | Final line has no newline | Display it like any other selected line |
591
+
592
+ ## `write`: create a new file only
593
+
594
+ ### Create a multiline file
595
+
596
+ ```sh
597
+ rwe write hello.txt 'First line
598
+ Second line
599
+ Third line'
600
+ ```
601
+
602
+ `CONTENT` becomes the complete file content. `rwe` does not append a newline,
603
+ remove a newline, trim spaces, expand variables, or otherwise normalize the
604
+ argument. In particular:
605
+
606
+ ```sh
607
+ rwe write no-final-newline.txt 'last line'
608
+ rwe write with-final-newline.txt 'last line
609
+ '
610
+ ```
611
+
612
+ These produce different bytes: only the second file ends with a newline.
613
+
614
+ Create an empty file with:
615
+
616
+ ```sh
617
+ rwe write empty.txt ''
618
+ ```
619
+
620
+ ### Existing files are never overwritten
621
+
622
+ If `FILE` already exists, `write` fails and leaves it unchanged:
623
+
624
+ ```text
625
+ rwe: refusing to overwrite 'hello.txt': it already exists; use 'rwe edit', or remove the file before using 'rwe write'
626
+ ```
627
+
628
+ This protection uses `os.open` with `O_EXCL`, so file creation and the
629
+ existence check happen atomically. It does not rely on a separate “check,
630
+ then create” sequence.
631
+
632
+ To change part of an existing file, use `edit`. To replace the entire file,
633
+ explicitly remove it using your preferred file-management command and then
634
+ run `write` again. `rwe` intentionally has no `delete` or force-overwrite
635
+ command.
636
+
637
+ Parent directories are not created. For example, this fails if `missing/`
638
+ does not already exist:
639
+
640
+ ```sh
641
+ rwe write missing/file.txt 'content'
642
+ ```
643
+
644
+ ### Write from standard input
645
+
646
+ Use `-` in place of `CONTENT`:
647
+
648
+ ```sh
649
+ printf 'First line\nSecond line\n' | rwe write new.txt -
650
+ ```
651
+
652
+ Or use a quoted here-document:
653
+
654
+ ```sh
655
+ rwe write new.txt - <<'EOF'
656
+ Literal $HOME and 'quotes'
657
+ Second line
658
+ EOF
659
+ ```
660
+
661
+ Standard input is read completely before the exclusive file creation is
662
+ attempted. The supplied bytes are written as-is; they are not UTF-8 decoded
663
+ and re-encoded on this path.
664
+
665
+ ### Write success output
666
+
667
+ A successful write prints a message like:
668
+
669
+ ```text
670
+ Created hello.txt (29 bytes)
671
+ ```
672
+
673
+ The byte count is the encoded content length, not a character count.
674
+
675
+ ## `edit`: replace original lines
676
+
677
+ ### Basic form
678
+
679
+ ```sh
680
+ rwe edit FILE EDITS
681
+ ```
682
+
683
+ `EDITS` is one argument containing one or more blocks. Each block starts at
684
+ the beginning of a line:
685
+
686
+ ```text
687
+ HEX_ADDRESS: replacement content
688
+ ```
689
+
690
+ For example:
691
+
692
+ ```sh
693
+ rwe edit notes.txt '01: Replacement for original line 01
694
+ 02: Replacement for original line 02'
695
+ ```
696
+
697
+ Each block replaces exactly one original line. Its replacement may itself
698
+ contain zero characters, one line, or multiple lines.
699
+
700
+ ### Multiple blocks and multiline replacements
701
+
702
+ ```sh
703
+ rwe edit notes.txt '01: First replacement line
704
+ Second line in the replacement for original 01
705
+ 02: Replacement for original line 02
706
+ b7: Replacement for original line b7'
707
+ ```
708
+
709
+ This command addresses three original lines:
710
+
711
+ - Original `01` becomes two lines.
712
+ - Original `02` becomes one line.
713
+ - Original `b7` becomes one line.
714
+
715
+ The second and third addresses are still interpreted against the original
716
+ file; the expansion at `01` does not move them.
717
+
718
+ ### Original-address rules
719
+
720
+ 1. Read the file to obtain current addresses.
721
+ 2. Build one or more replacement blocks using those addresses.
722
+ 3. Pass all blocks in one `edit` invocation.
723
+ 4. `rwe` validates every block before saving anything.
724
+ 5. Replacements are applied from the highest original address to the lowest.
725
+ 6. Read the resulting file before planning another edit.
726
+
727
+ Block order in `EDITS` does not determine application order. These are
728
+ semantically equivalent:
729
+
730
+ ```text
731
+ 01: First
732
+ 03: Third
733
+ ```
734
+
735
+ ```text
736
+ 03: Third
737
+ 01: First
738
+ ```
739
+
740
+ Both replace original lines 1 and 3. Duplicate addresses are never merged or
741
+ applied sequentially.
742
+
743
+ ### What `edit` does not do
744
+
745
+ - `02:` makes original line 2 **empty**; it does not delete the line.
746
+ - A multiline replacement expands a line; there is no separate insertion-only
747
+ operation.
748
+ - There is no “current line 3 after previous block” addressing mode.
749
+ - There is no range replacement syntax such as `01:03: text`. The first colon
750
+ ends the address, so that form is content for address `01`, not a range.
751
+ - There is no regular-expression or search-and-replace mode.
752
+ - An empty file has no addressable lines, so it cannot be populated with
753
+ `edit`; remove it and use `write` instead.
754
+
755
+ ### Header recognition
756
+
757
+ A new block starts only when a line begins with one or more hexadecimal digits
758
+ immediately followed by `:`. Examples recognized as headers:
759
+
760
+ ```text
761
+ 1: content
762
+ 01: content
763
+ B7: content
764
+ dead: content
765
+ ```
766
+
767
+ The address need not have the same width shown by `read`. `1` and `01` both
768
+ mean original line 1.
769
+
770
+ These continuation lines are **not** headers:
771
+
772
+ ```text
773
+ 02: indented, so this is content
774
+ not-hex: content
775
+ http://example.com
776
+ 3.14: content
777
+ ```
778
+
779
+ Because only the beginning of a line can start a header, a colon elsewhere in
780
+ normal content has no special meaning.
781
+
782
+ Non-whitespace content before the first recognized header is an error. Leading
783
+ blank or whitespace-only lines before the first block are ignored.
784
+
785
+ ### Spaces and tabs after the colon
786
+
787
+ One ASCII space or one tab immediately after the colon is treated as a
788
+ separator and removed. It is optional:
789
+
790
+ ```text
791
+ 01: Replacement # Replacement content is "Replacement"
792
+ 01:Replacement # Replacement content is "Replacement"
793
+ ```
794
+
795
+ If there are multiple spaces, only the first is removed:
796
+
797
+ ```text
798
+ 01: indented
799
+ ```
800
+
801
+ produces content beginning with two spaces.
802
+
803
+ On continuation lines, indentation and other whitespace are preserved exactly
804
+ as supplied in the edit argument.
805
+
806
+ ### Empty replacements and blank lines
807
+
808
+ Given an original file:
809
+
810
+ ```text
811
+ 01: A
812
+ 02: B
813
+ 03: C
814
+ 04: D
815
+ ```
816
+
817
+ this command:
818
+
819
+ ```sh
820
+ rwe edit notes.txt '01:
821
+ 03: Replacement
822
+
823
+ '
824
+ ```
825
+
826
+ has the following meaning:
827
+
828
+ - Original `01` becomes an empty line.
829
+ - Original `03` becomes `Replacement` followed by an empty line.
830
+
831
+ The result is:
832
+
833
+ ```text
834
+ 01:
835
+ 02: B
836
+ 03: Replacement
837
+ 04:
838
+ 05: D
839
+ ```
840
+
841
+ To understand blank lines, remember these parser rules:
842
+
843
+ - The newline before the next header terminates the previous block; it is not
844
+ an additional content line.
845
+ - One newline at the very end of the `EDITS` argument is treated as the final
846
+ block terminator.
847
+ - Extra newlines beyond those terminators become blank replacement lines.
848
+ - To make the last block end in a blank line, include an extra blank line
849
+ before the closing shell quote.
850
+
851
+ ### Escaping a content line that looks like a header
852
+
853
+ Suppose original line `01` should become:
854
+
855
+ ```text
856
+ First replacement line
857
+ dead: This must remain literal content
858
+ ```
859
+
860
+ Because `dead` is valid hexadecimal, an unescaped continuation line beginning
861
+ `dead:` would start a new block. Prefix it with one backslash:
862
+
863
+ ```sh
864
+ rwe edit notes.txt '01: First replacement line
865
+ \dead: This must remain literal content
866
+ 02: Replacement for original line 02'
867
+ ```
868
+
869
+ On continuation lines, a backslash is removed only when the text after it
870
+ would otherwise be recognized as an edit header. Other backslashes remain
871
+ unchanged. The escape applies to continuation lines, not to the first header
872
+ of a block.
873
+
874
+ In POSIX single quotes the backslash reaches `rwe` literally. When generating
875
+ edit strings in another programming language, account for that language's own
876
+ backslash escaping as well.
877
+
878
+ ### Edit from standard input
879
+
880
+ Use `-` as the entire `EDITS` argument:
881
+
882
+ ```sh
883
+ rwe edit notes.txt - <<'EOF'
884
+ 01: Replacement from standard input
885
+ 03: Another original-line replacement
886
+ EOF
887
+ ```
888
+
889
+ This is useful for generated edit scripts and content containing quotes. The
890
+ edit syntax is otherwise identical, including the rule that one final newline
891
+ terminates the last block.
892
+
893
+ ### Validation is all-or-nothing before saving
894
+
895
+ The file is not intentionally changed if any of these conditions occurs:
896
+
897
+ - No valid edit block exists
898
+ - Non-whitespace content appears before the first block
899
+ - An address is zero or malformed as a header
900
+ - An address appears more than once, including aliases such as `1` and `01`
901
+ - Any address is beyond the original file's last line
902
+ - Any original line is not valid UTF-8
903
+ - Standard-input edit data is not valid UTF-8
904
+ - The target is not a regular file after resolving symbolic links
905
+
906
+ For example, this rejects the **entire** operation rather than applying the
907
+ valid first block:
908
+
909
+ ```sh
910
+ rwe edit three-lines.txt '01: Valid replacement
911
+ ff: Invalid if the file has only three lines'
912
+ ```
913
+
914
+ On success, `rwe` prints:
915
+
916
+ ```text
917
+ Edited notes.txt (2 original line addresses)
918
+ ```
919
+
920
+ The count is the number of distinct original addresses, not the number of
921
+ replacement lines.
922
+
923
+ ## Input, output, paths, and encoding
924
+
925
+ ### Standard output and standard error
926
+
927
+ | Stream | Used for |
928
+ |---|---|
929
+ | Standard output | Numbered `read` content, success messages, help, version |
930
+ | Standard error | File/validation errors, usage errors, 1000-line continuation notices |
931
+
932
+ The continuation notice does not make a successful `read` fail; its exit code
933
+ is still 0.
934
+
935
+ The numbered `read` format is designed for humans and for constructing later
936
+ `edit` commands. There is no JSON or machine-readable output mode. Programs
937
+ parsing it must account for variable address width and the separator space.
938
+ Success messages also go to stdout, so redirect or ignore them when a script
939
+ needs only another stream's data.
940
+
941
+ ### Encoding and line endings
942
+
943
+ - `read` decodes selected content as UTF-8 and reports an error for invalid
944
+ selected content.
945
+ - `edit` validates the entire original file as UTF-8 before applying changes.
946
+ - Direct `write CONTENT` encodes the argument as UTF-8.
947
+ - `write FILE -` writes standard-input bytes as supplied.
948
+ - `read` recognizes LF (`\n`) and strips a preceding CR for CRLF display.
949
+ - A lone carriage return is not treated as a line separator in the original
950
+ file.
951
+ - CRLF and CR characters inside the `EDITS` argument itself are normalized to
952
+ LF for parsing; original file line-ending preservation is handled
953
+ separately when replacements are rendered.
954
+ - No character-set auto-detection or encoding option is provided.
955
+ - Binary files are unsupported.
956
+
957
+ ### Relative and absolute paths
958
+
959
+ Relative paths are resolved against the process's current working directory.
960
+ Absolute paths work normally. There is no project-root discovery, ignore-file
961
+ processing, recursive directory traversal, or glob expansion performed by
962
+ `rwe` itself. Your shell may expand unquoted wildcards before `rwe` sees them.
963
+
964
+ For `edit`, symbolic links are resolved and the target file is replaced; the
965
+ symbolic link itself remains a link.
966
+
967
+ ## Safety, preservation, and limitations
968
+
969
+ ### What is preserved by `edit`
970
+
971
+ - Existing file permission bits are copied to the temporary file.
972
+ - Each replaced original line keeps its original LF or CRLF ending.
973
+ - Unselected lines retain their original bytes after the whole file has
974
+ passed UTF-8 validation.
975
+ - A one-line replacement of a final line without a newline remains without a
976
+ final newline.
977
+ - When a multiline replacement expands an unterminated final line, the last
978
+ new line remains unterminated; earlier inserted lines use the file's first
979
+ encountered line-ending style, defaulting to LF.
980
+ - A symbolic link remains a symbolic link while its target is edited.
981
+
982
+ ### Atomic save model
983
+
984
+ `edit` follows this sequence:
985
+
986
+ 1. Parse all edit blocks.
987
+ 2. Resolve the target and read the original file.
988
+ 3. Validate the file type, UTF-8 content, and every address.
989
+ 4. Build replacements in memory, from bottom to top.
990
+ 5. Create a temporary file in the target's directory.
991
+ 6. Copy the original permission bits and write the complete result.
992
+ 7. Replace the target with `os.replace`.
993
+ 8. Remove the temporary file if saving fails before replacement.
994
+
995
+ This avoids exposing a partially written result through the target path when
996
+ an ordinary write failure occurs. It does **not** provide transactions across
997
+ multiple files, backups, rollback after a successful replacement, file
998
+ locking, or conflict detection.
999
+
1000
+ ### Important limitations
1001
+
1002
+ - **Whole-file rewrite:** `edit` reads and writes the complete file. Memory
1003
+ use and I/O grow with file size.
1004
+ - **Concurrent writers:** `rwe` does not lock files or compare modification
1005
+ times. Another process's changes can be overwritten by a later `edit`.
1006
+ - **Metadata:** permission bits are preserved, but ownership, ACLs, extended
1007
+ attributes, hard-link identity, timestamps, and other filesystem-specific
1008
+ metadata are not guaranteed to survive target replacement.
1009
+ - **Durability:** the implementation does not call `fsync` on the temporary
1010
+ file or parent directory. Atomic replacement is not a guarantee against
1011
+ every power-loss or filesystem-failure scenario.
1012
+ - **Parent directories:** `write` does not create them.
1013
+ - **Line deletion:** unsupported. Emptying a line is not deleting it.
1014
+ - **Configuration:** there are no configuration files, environment-variable
1015
+ options, plugins, or interactive prompts.
1016
+ - **Read performance:** only selected lines are decoded and formatted, but the
1017
+ remainder is still scanned for total line count and address width.
1018
+
1019
+ ## Errors, exit codes, and troubleshooting
1020
+
1021
+ ### Exit codes
1022
+
1023
+ | Code | Meaning | Examples |
1024
+ |---|---|---|
1025
+ | `0` | Success | Read, write, edit, help, version completed |
1026
+ | `1` | Runtime or validation error | Missing file, existing write target, bad UTF-8, bad range, duplicate edit address |
1027
+ | `2` | Command-line usage error | Unknown command, missing operand, too many arguments |
1028
+ | `130` | Interrupted by Ctrl+C | Keyboard interrupt |
1029
+
1030
+ When output is piped to a consumer that closes early, such as some uses of
1031
+ `head`, a broken output pipe is handled as normal termination rather than a
1032
+ Python traceback.
1033
+
1034
+ ### Common mistakes
1035
+
1036
+ #### “My multiline write failed with a usage error”
1037
+
1038
+ Quote the complete content so it is one argument:
1039
+
1040
+ ```sh
1041
+ rwe write file.txt 'line one
1042
+ line two'
1043
+ ```
1044
+
1045
+ Do not pass separate unquoted arguments for each word.
1046
+
1047
+ #### “`write` refuses to create my file”
1048
+
1049
+ That is expected if the path already exists. Use `read` and `edit`, or remove
1050
+ the file deliberately before recreating it. There is no overwrite flag.
1051
+
1052
+ #### “My second edit changed the wrong line”
1053
+
1054
+ Use addresses from a fresh `read` before each invocation. Within one command,
1055
+ addresses use the original snapshot; across commands, earlier edits may have
1056
+ changed line positions.
1057
+
1058
+ #### “Why did original line 03 become output line 04?”
1059
+
1060
+ An earlier replacement added a line. The address still correctly targeted
1061
+ original line 03; its result simply appears later in the new file. See the
1062
+ [complete workflow](#complete-workflow).
1063
+
1064
+ #### “Why is `64` not line 64?”
1065
+
1066
+ Addresses are hexadecimal. `64` means decimal 100. Decimal 64 is hexadecimal
1067
+ `40`.
1068
+
1069
+ #### “Why is my first line `001` instead of `01`?”
1070
+
1071
+ The file has at least 256 lines, so all displayed addresses use three digits.
1072
+
1073
+ #### “My content line `dead: text` became a separate edit”
1074
+
1075
+ `dead` is valid hexadecimal. Escape it as `\dead: text` on a continuation
1076
+ line.
1077
+
1078
+ #### “`02:` did not remove line 2”
1079
+
1080
+ That syntax replaces line 2 with an empty line. Line deletion is not
1081
+ implemented.
1082
+
1083
+ #### “I only see 1000 lines”
1084
+
1085
+ Use the continuation address printed on standard error:
1086
+
1087
+ ```sh
1088
+ rwe read large.txt 3e9:
1089
+ ```
1090
+
1091
+ or request a smaller range explicitly.
1092
+
1093
+ #### “I see a UTF-8 error”
1094
+
1095
+ The tool does not support arbitrary encodings or binary files. Convert the
1096
+ file to UTF-8 with another tool before using `rwe`.
1097
+
1098
+ ## Development and project layout
1099
+
1100
+ ```text
1101
+ .
1102
+ ├── pyproject.toml # Package metadata, dependencies, console scripts
1103
+ ├── README.md # Complete user and developer guide
1104
+ ├── LICENSE # Apache License 2.0 full text
1105
+ ├── .github/
1106
+ │ └── workflows/
1107
+ │ └── publish.yml # vX.Y.Z tag-triggered PyPI publication
1108
+ ├── src/
1109
+ │ └── rwe/
1110
+ │ ├── __init__.py # Package version
1111
+ │ ├── __main__.py # `python -m rwe` entry point
1112
+ │ └── cli.py # Parsing, file operations, messages, exit codes
1113
+ └── tests/
1114
+ └── test_cli.py # Standard-library unittest suite
1115
+ ```
1116
+
1117
+ The two console-script names are declared in `pyproject.toml` and both point
1118
+ to `rwe.cli:main`.
1119
+
1120
+ ### Run tests
1121
+
1122
+ From the project root:
1123
+
1124
+ ```sh
1125
+ PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src python3 -m unittest discover -s tests -v
1126
+ ```
1127
+
1128
+ The suite uses `unittest`, `tempfile`, mocked streams, and real subprocess
1129
+ calls. It covers:
1130
+
1131
+ - Hexadecimal formatting and width growth
1132
+ - Single, finite, and open-ended ranges
1133
+ - Empty files, unterminated final lines, and the 1000-line cap
1134
+ - Exclusive creation and exact multiline content
1135
+ - Multiple original-address edits and multiline expansion
1136
+ - Empty replacements, duplicate and out-of-range rejection
1137
+ - Escaped headers and standard input
1138
+ - CRLF and final-newline preservation
1139
+ - Permissions, symbolic links, invalid UTF-8, and failed replacement cleanup
1140
+ - Help, version, usage errors, and the real `python -m rwe` surface
1141
+
1142
+ The tests require no third-party test runner.
1143
+
1144
+ ### Build distributions
1145
+
1146
+ With the `build` package available:
1147
+
1148
+ ```sh
1149
+ python3 -m build --no-isolation
1150
+ ```
1151
+
1152
+ Outputs are written to `dist/`:
1153
+
1154
+ ```text
1155
+ dist/read_write_edit_tools-0.1.0-py3-none-any.whl
1156
+ dist/read_write_edit_tools-0.1.0.tar.gz
1157
+ ```
1158
+
1159
+ The wheel and source distribution include the Apache-2.0 `LICENSE`. Package
1160
+ metadata declares `License-Expression: Apache-2.0`.
1161
+
1162
+ An equivalent uv build command is:
1163
+
1164
+ ```sh
1165
+ uv build
1166
+ ```
1167
+
1168
+ ### Automated PyPI releases with GitHub Actions
1169
+
1170
+ The distribution published to PyPI is named **`read-write-edit-tools`**.
1171
+ Pushing a version tag runs `.github/workflows/publish.yml`, which builds and
1172
+ publishes that distribution with
1173
+ [PyPI Trusted Publishing](https://docs.pypi.org/trusted-publishers/). No
1174
+ long-lived PyPI API token or password is stored in GitHub Secrets.
1175
+
1176
+ The workflow has two jobs:
1177
+
1178
+ 1. **`build`** checks out the tag, validates its version, runs the full test
1179
+ suite, builds the wheel and source distribution, checks metadata and both
1180
+ installed entry points, and stores the exact distributions as a workflow
1181
+ artifact.
1182
+ 2. **`publish`** runs only after `build` succeeds. It downloads those exact
1183
+ artifacts and publishes them to PyPI using GitHub's short-lived OIDC
1184
+ identity. Only this job receives `id-token: write`; the build job has only
1185
+ `contents: read`.
1186
+
1187
+ The publish job does **not** require a GitHub environment. The optional
1188
+ Environment name is left blank both in the workflow and in the PyPI Trusted
1189
+ Publisher configuration. The PyPI action generates signed attestations by
1190
+ default in the Trusted Publishing flow.
1191
+
1192
+ #### One-time repository and PyPI setup
1193
+
1194
+ Perform these steps before the first tag. They require repository
1195
+ administration access and a PyPI account; they cannot be completed by editing
1196
+ this repository alone.
1197
+
1198
+ 1. Use the public repository
1199
+ **[llaa33219/read-write-edit-tools](https://github.com/llaa33219/read-write-edit-tools)**,
1200
+ including `.github/workflows/publish.yml`. No GitHub Environment needs to
1201
+ be created.
1202
+
1203
+ 2. Configure PyPI to trust **this exact repository and workflow filename**.
1204
+ The optional Environment name must be left **blank**:
1205
+
1206
+ | PyPI Trusted Publisher field | Required value |
1207
+ |---|---|
1208
+ | PyPI project name | `read-write-edit-tools` |
1209
+ | Owner | `llaa33219` |
1210
+ | Repository name | `read-write-edit-tools` |
1211
+ | Workflow name | `publish.yml` |
1212
+ | Environment name | **Leave blank (optional)** |
1213
+
1214
+ For the **first release**, create a **pending publisher** under your PyPI
1215
+ account's **Publishing** page. This lets the first successful OIDC upload
1216
+ create the project without a manual initial upload. Official instructions:
1217
+ <https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/>.
1218
+
1219
+ If the project already exists on PyPI, add the publisher from that
1220
+ project's **Publishing** management page instead:
1221
+ <https://docs.pypi.org/trusted-publishers/adding-a-publisher/>.
1222
+
1223
+ A pending publisher does not reserve the name. If somebody else registers
1224
+ `read-write-edit-tools` before the first upload, the pending publisher is
1225
+ invalidated and ownership must be resolved on PyPI.
1226
+
1227
+ 3. Do **not** add a PyPI username, password, or API token to the workflow. If
1228
+ your organization prohibits OIDC, use a separately approved secret-based
1229
+ process instead; the supplied workflow intentionally uses Trusted
1230
+ Publishing.
1231
+
1232
+ #### Release a new version
1233
+
1234
+ Suppose the new version is `0.2.0`.
1235
+
1236
+ 1. Update **both** version declarations to `0.2.0`:
1237
+
1238
+ ```toml
1239
+ # pyproject.toml
1240
+ [project]
1241
+ version = "0.2.0"
1242
+ ```
1243
+
1244
+ ```python
1245
+ # src/rwe/__init__.py
1246
+ __version__ = "0.2.0"
1247
+ ```
1248
+
1249
+ Also update documentation examples that intentionally display the current
1250
+ version, if any.
1251
+
1252
+ 2. Review the changes and run the local verification commands:
1253
+
1254
+ ```sh
1255
+ PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src python3 -m unittest discover -s tests -v
1256
+ uv build
1257
+ ```
1258
+
1259
+ 3. Commit the release changes using your normal review process, then create
1260
+ and push the tag from the intended release commit:
1261
+
1262
+ ```sh
1263
+ git tag v0.2.0
1264
+ git push origin v0.2.0
1265
+ ```
1266
+
1267
+ The workflow accepts only tags matching **`vX.Y.Z`** with numeric `X`, `Y`,
1268
+ and `Z`, such as `v0.2.0` or `v1.10.3`. Tags such as `0.2.0`, `v0.2`,
1269
+ `v0.2.0-rc1`, and arbitrary release names do not match this release
1270
+ workflow.
1271
+
1272
+ 4. GitHub rejects the release before building if the tag's `X.Y.Z` does not
1273
+ exactly equal `[project].version`. Keep `src/rwe/__init__.py` equal too so
1274
+ `rwe --version` reports the same release.
1275
+
1276
+ 5. Watch **GitHub → Actions → Publish to PyPI**. The workflow stops without
1277
+ uploading if tests, version checks, the build, or wheel smoke tests fail.
1278
+ There is no GitHub Environment approval gate in this configuration.
1279
+
1280
+ 6. After a successful run, verify the published package and both execution
1281
+ modes:
1282
+
1283
+ ```sh
1284
+ uv tool install read-write-edit-tools
1285
+ rwe --version
1286
+ uvx --from read-write-edit-tools rwe --version
1287
+ ```
1288
+
1289
+ #### Release operational notes
1290
+
1291
+ - PyPI filenames are immutable. A version that has already been uploaded
1292
+ cannot be replaced by pushing the same tag again. Increment the version and
1293
+ create a new tag instead.
1294
+ - Deleting or recreating a tag does not retract distributions from PyPI. Use
1295
+ PyPI's yanking process when a published release must be discouraged.
1296
+ - The workflow uploads distributions to **real PyPI**, not TestPyPI.
1297
+ - It does not create a GitHub Release or generate release notes. The GitHub
1298
+ Actions artifact is a temporary handoff between jobs, not the public PyPI
1299
+ download page.
1300
+ - Forks and differently named workflows are not trusted by the publisher
1301
+ configured for the original repository.
1302
+ - A first end-to-end publication can only be verified after the external PyPI
1303
+ publisher has been configured and a real tag has been pushed.
1304
+
1305
+ ### Implementation notes
1306
+
1307
+ - `src/rwe/cli.py` contains a small hand-written argument dispatcher rather
1308
+ than `argparse`, avoiding that startup cost.
1309
+ - Hexadecimal validation and edit-header parsing avoid importing `re`.
1310
+ - `tempfile` is imported only when `edit` needs it, keeping `read` and `write`
1311
+ startup lighter.
1312
+ - `read` formats at most 1000 selected lines, then counts remaining newlines
1313
+ in 1 MiB binary chunks to determine total width.
1314
+ - `write` uses `O_WRONLY | O_CREAT | O_EXCL` for atomic no-overwrite creation.
1315
+ - `edit` parses the entire edit argument, validates against the original,
1316
+ replaces addresses bottom-up, and saves via a sibling temporary file and
1317
+ `os.replace`.
1318
+ - Expected failures use the internal `RweError` exception and produce concise
1319
+ English messages rather than tracebacks.
1320
+
1321
+ ## License
1322
+
1323
+ This project is licensed under the **Apache License, Version 2.0**.
1324
+
1325
+ The complete license text is in [LICENSE](LICENSE). The same license is
1326
+ included in built distributions. The official license page is:
1327
+
1328
+ <https://www.apache.org/licenses/LICENSE-2.0>
1329
+
1330
+ Unless required by applicable law or agreed to in writing, software distributed
1331
+ under the License is distributed on an **“AS IS” BASIS, WITHOUT WARRANTIES OR
1332
+ CONDITIONS OF ANY KIND**, either express or implied. See the License for the
1333
+ specific language governing permissions and limitations under the License.