├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE2 ├── LICENSE-MIT ├── README.md └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | #Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | 13 | #Added by cargo 14 | # 15 | #already existing elements are commented out 16 | 17 | /target 18 | #**/*.rs.bk 19 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "ansi_term" 5 | version = "0.11.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 9 | ] 10 | 11 | [[package]] 12 | name = "atty" 13 | version = "0.2.11" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | dependencies = [ 16 | "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", 17 | "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 18 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 19 | ] 20 | 21 | [[package]] 22 | name = "bcp" 23 | version = "0.4.0" 24 | dependencies = [ 25 | "pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 26 | "structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", 27 | ] 28 | 29 | [[package]] 30 | name = "bitflags" 31 | version = "1.0.4" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | 34 | [[package]] 35 | name = "clap" 36 | version = "2.32.0" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | dependencies = [ 39 | "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 40 | "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 41 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 42 | "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 43 | "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 44 | "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 45 | "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", 46 | ] 47 | 48 | [[package]] 49 | name = "heck" 50 | version = "0.3.1" 51 | source = "registry+https://github.com/rust-lang/crates.io-index" 52 | dependencies = [ 53 | "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 54 | ] 55 | 56 | [[package]] 57 | name = "kernel32-sys" 58 | version = "0.2.2" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | dependencies = [ 61 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 62 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 63 | ] 64 | 65 | [[package]] 66 | name = "libc" 67 | version = "0.2.50" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | 70 | [[package]] 71 | name = "pbr" 72 | version = "1.0.1" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | dependencies = [ 75 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 76 | "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", 77 | "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 78 | "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 79 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 80 | ] 81 | 82 | [[package]] 83 | name = "proc-macro2" 84 | version = "0.4.27" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | dependencies = [ 87 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | ] 89 | 90 | [[package]] 91 | name = "quote" 92 | version = "0.6.11" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | dependencies = [ 95 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 96 | ] 97 | 98 | [[package]] 99 | name = "redox_syscall" 100 | version = "0.1.51" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | 103 | [[package]] 104 | name = "redox_termios" 105 | version = "0.1.1" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | dependencies = [ 108 | "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", 109 | ] 110 | 111 | [[package]] 112 | name = "strsim" 113 | version = "0.7.0" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | 116 | [[package]] 117 | name = "structopt" 118 | version = "0.2.15" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | dependencies = [ 121 | "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", 122 | "structopt-derive 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", 123 | ] 124 | 125 | [[package]] 126 | name = "structopt-derive" 127 | version = "0.2.15" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | dependencies = [ 130 | "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 131 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 132 | "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", 133 | "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", 134 | ] 135 | 136 | [[package]] 137 | name = "syn" 138 | version = "0.15.29" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | dependencies = [ 141 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", 142 | "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", 143 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 144 | ] 145 | 146 | [[package]] 147 | name = "termion" 148 | version = "1.5.1" 149 | source = "registry+https://github.com/rust-lang/crates.io-index" 150 | dependencies = [ 151 | "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", 152 | "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", 153 | "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 154 | ] 155 | 156 | [[package]] 157 | name = "textwrap" 158 | version = "0.10.0" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | dependencies = [ 161 | "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 162 | ] 163 | 164 | [[package]] 165 | name = "time" 166 | version = "0.1.42" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | dependencies = [ 169 | "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", 170 | "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", 171 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 172 | ] 173 | 174 | [[package]] 175 | name = "unicode-segmentation" 176 | version = "1.2.1" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | 179 | [[package]] 180 | name = "unicode-width" 181 | version = "0.1.5" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | 184 | [[package]] 185 | name = "unicode-xid" 186 | version = "0.1.0" 187 | source = "registry+https://github.com/rust-lang/crates.io-index" 188 | 189 | [[package]] 190 | name = "vec_map" 191 | version = "0.8.1" 192 | source = "registry+https://github.com/rust-lang/crates.io-index" 193 | 194 | [[package]] 195 | name = "winapi" 196 | version = "0.2.8" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | 199 | [[package]] 200 | name = "winapi" 201 | version = "0.3.6" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | dependencies = [ 204 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 205 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 206 | ] 207 | 208 | [[package]] 209 | name = "winapi-build" 210 | version = "0.1.1" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | 213 | [[package]] 214 | name = "winapi-i686-pc-windows-gnu" 215 | version = "0.4.0" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | 218 | [[package]] 219 | name = "winapi-x86_64-pc-windows-gnu" 220 | version = "0.4.0" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | 223 | [metadata] 224 | "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 225 | "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" 226 | "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" 227 | "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" 228 | "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 229 | "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 230 | "checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" 231 | "checksum pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "deb73390ab68d81992bd994d145f697451bb0b54fd39738e72eef32458ad6907" 232 | "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" 233 | "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" 234 | "checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" 235 | "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" 236 | "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" 237 | "checksum structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "3d0760c312538987d363c36c42339b55f5ee176ea8808bbe4543d484a291c8d1" 238 | "checksum structopt-derive 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "528aeb7351d042e6ffbc2a6fb76a86f9b622fdf7c25932798e7a82cb03bc94c6" 239 | "checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2" 240 | "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" 241 | "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" 242 | "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" 243 | "checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" 244 | "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" 245 | "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" 246 | "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" 247 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 248 | "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" 249 | "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 250 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 251 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 252 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bcp" 3 | version = "0.4.0" 4 | authors = ["Simon Heath "] 5 | edition = "2018" 6 | description = "A convenient program for copying blocks of bytes within files." 7 | license = "MIT/Apache-2.0" 8 | repository = "https://github.com/icefoxen/bcp" 9 | keywords = ["file", "cli", "terminal"] 10 | categories = ["command-line-utilities", "filesystem"] 11 | readme = "README.md" 12 | 13 | [dependencies] 14 | structopt = "0.2" 15 | pbr = "1" 16 | -------------------------------------------------------------------------------- /LICENSE-APACHE2: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017 ggez-dev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bcp 2 | 3 | A convenient block copy program. `bcp` is intended to copy contiguous 4 | chunks of files from point A to point B. Want to cookie-cutter a 5 | piece out of of a file and plop it down in the middle of another file? 6 | Here you go. 7 | 8 | The main use case I want for myself is doing light surgery to disk 9 | images, such as "copy this bootloader block into the image at this 10 | offset". 11 | 12 | # Usage 13 | 14 | ``` 15 | $ bcp --help 16 | bcp 0.2.0 17 | Simon Heath 18 | A convenient program for copying blocks of bytes within files. 19 | 20 | USAGE: 21 | bcp [FLAGS] [OPTIONS] 22 | 23 | FLAGS: 24 | -v, --verbose Verbose output, with progress bar. 25 | -h, --help Prints help information 26 | -V, --version Prints version information 27 | 28 | OPTIONS: 29 | -s, --src-offset The byte offset in the source file to start reading from. Must not be larger than 30 | the file in question. [default: 0] 31 | -d, --dst-offset The byte offset in the destination file to start writing to. Must not be larger 32 | than the file in question, and the file must exist. [default: 0] 33 | -c, --count The number of bytes to copy. Defaults to "all of them", from the `src-offset` to 34 | the end of the file. Asking to read past the end of the source file is an error. 35 | 36 | ARGS: 37 | The source file to copy from. 38 | The destination file to copy to. Will create the file if it does not exist. 39 | ``` 40 | 41 | # Why? 42 | 43 | Basically, the goal is to make a nicer version of the traditional Unix 44 | utility `dd`, because `dd` is just... weird. See [the Jargon file 45 | entry](http://www.catb.org/jargon/html/D/dd.html) for it, particularly 46 | lines like "the user interface for it is clearly a prank" and "it has 47 | no exact replacement". So, why not just make a replacement? 48 | 49 | In particular: I want a Unix-y command line interface, I want to be 50 | able to blit large chunks of files from point A to point B, and I 51 | really don't need EBCDIC translation, byte swapping, "fail if the 52 | output file already exists" being classified as a conversion, a 53 | default block size of 512 bytes because that's how big hard drive 54 | blocks were on a PDP-11, or the ability to have it catch a `SIGUSR1` 55 | and print I/O statistics. I want it to copy bytes, and that's all. 56 | 57 | ...Okay, and have a progress bar. But that's it. Honest! 58 | 59 | # License 60 | 61 | MIT/Apache-2 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | //! A small tool similar to the useful parts of the Unix program `dd`. 2 | //! See the [crates.io page](https://crates.io/crates/bcp) for more info. 3 | 4 | use std::fs; 5 | use std::io::{self, Read, Seek, Write}; 6 | use std::path::PathBuf; 7 | use std::process; 8 | 9 | use pbr; 10 | use structopt::{clap::AppSettings, StructOpt}; 11 | 12 | /// Command line options. 13 | #[derive(Debug, StructOpt)] 14 | #[structopt(raw(global_settings = "&[AppSettings::DeriveDisplayOrder]"))] 15 | struct Opt { 16 | /// The source file to copy from. 17 | #[structopt(name = "SRC", parse(from_os_str))] 18 | src: PathBuf, 19 | 20 | /// The destination file to copy to. Will create the file 21 | /// if it does not exist. 22 | #[structopt(name = "DST", parse(from_os_str))] 23 | dst: PathBuf, 24 | 25 | /// The byte offset in the source file to start reading from. 26 | /// Must not be larger than the file in question. 27 | #[structopt(short = "s", long = "src-offset", default_value = "0")] 28 | src_offset: u64, 29 | 30 | /// The byte offset in the destination file to start writing to. 31 | /// Must not be larger than the file in question, and the file 32 | /// must exist. 33 | #[structopt(short = "d", long = "dst-offset", default_value = "0")] 34 | dst_offset: u64, 35 | 36 | /// Size of the read/write buffer to use. 37 | #[structopt(short = "b", long = "buffer-size", default_value = "1048576")] 38 | buffer_size: usize, 39 | 40 | /// The number of bytes to copy. Defaults to "all of them", 41 | /// from the `src-offset` to the end of the file. Asking to 42 | /// read past the end of the source file is an error. 43 | #[structopt(short = "c", long = "count")] 44 | count: Option, 45 | 46 | /// Verbose output, with progress bar. 47 | #[structopt(short = "v", long = "verbose")] 48 | verbose: bool, 49 | } 50 | 51 | /// Print an error message and quit. 52 | fn error(msg: &str) -> ! { 53 | eprintln!("ERROR: {}", msg); 54 | process::exit(1) 55 | } 56 | 57 | /// Exits if the command line options don't make sense. 58 | /// Returns the source file length, 'cause it's handy and 59 | /// there's no point in asking for it twice. 60 | fn sanity_check(opt: &Opt) -> u64 { 61 | // Check src file length. 62 | let src_metadata = opt.src.metadata().unwrap_or_else(|e| { 63 | let errmsg = format!("Could not get metadata for source file: {:?}", e); 64 | error(&errmsg) 65 | }); 66 | let src_len = src_metadata.len(); 67 | // TODO: Double-check for off-by-one 68 | if src_len <= opt.src_offset { 69 | error("source offset > source file size"); 70 | } 71 | 72 | // Check count is valid 73 | if let Some(c) = opt.count { 74 | // TODO: Double-check for off-by-one 75 | if c + opt.src_offset > src_len { 76 | error("Count + source offset > source file size"); 77 | } 78 | } 79 | 80 | // Check dest file length and properties. 81 | if opt.dst.exists() { 82 | if opt.dst.is_dir() { 83 | error("Destination must be a file."); 84 | } 85 | let dst_metadata = opt.dst.metadata().unwrap_or_else(|e| { 86 | let errmsg = format!("Could not get metadata for destination file: {:?}", e); 87 | error(&errmsg) 88 | }); 89 | // TODO: Double-check for off-by-one 90 | //println!("{} < {} ?", dst_metadata.len(), opt.dst_offset); 91 | if dst_metadata.len() < opt.dst_offset { 92 | error("destination offset > destination file size"); 93 | } 94 | } else if opt.dst_offset > 0 { 95 | error("destination file cannot have an offset if the file does not exist; the results of trying to seek past the end of a file are system-defined and thus probably not what you want.") 96 | } 97 | 98 | if opt.buffer_size == 0 { 99 | error("buffer size = 0. Finishing your copy would take a long, long time."); 100 | } 101 | 102 | src_len 103 | } 104 | 105 | /// Actually do the copy. 106 | fn copy_stuff(opt: &Opt, src_len: u64) { 107 | let mut src = fs::File::open(&opt.src).expect("Should never happen?"); 108 | let mut dst = fs::OpenOptions::new() 109 | .write(true) 110 | .create(true) 111 | .open(&opt.dst) 112 | .unwrap_or_else(|e| { 113 | let errmsg = format!("Could not open destination file for writing: {:?}", e); 114 | error(&errmsg) 115 | }); 116 | 117 | src.seek(io::SeekFrom::Start(opt.src_offset)) 118 | .expect("Should never happen?"); 119 | dst.seek(io::SeekFrom::Start(opt.dst_offset)) 120 | .expect("Should never happen?"); 121 | 122 | let copy_len = opt.count.unwrap_or(src_len); 123 | let mut src = src.take(copy_len); 124 | 125 | // Basically stolen from io::copy(). 126 | // We want a little more control over what's happening 127 | // than that gives us. 128 | let mut pb = if opt.verbose { 129 | let mut progress = pbr::ProgressBar::new(copy_len); 130 | progress.set_units(pbr::Units::Bytes); 131 | Some(progress) 132 | } else { 133 | None 134 | }; 135 | let mut buf = vec![0; opt.buffer_size]; 136 | loop { 137 | let len = match src.read(&mut buf) { 138 | Ok(0) => break, 139 | Ok(len) => len, 140 | Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue, 141 | Err(e) => { 142 | let errmsg = format!("Error reading file: {:?}", e); 143 | error(&errmsg) 144 | } 145 | }; 146 | dst.write_all(&buf[..len]).unwrap_or_else(|e| { 147 | let errmsg = format!("Error reading file: {:?}", e); 148 | error(&errmsg) 149 | }); 150 | if let Some(ref mut p) = pb { 151 | p.add(len as u64); 152 | } 153 | } 154 | } 155 | 156 | fn main() { 157 | let opt = Opt::from_args(); 158 | let src_len = sanity_check(&opt); 159 | copy_stuff(&opt, src_len); 160 | } 161 | 162 | #[cfg(test)] 163 | mod test {} 164 | --------------------------------------------------------------------------------