Download a file from the device, and extract its contents. Arguments: path(str): Path to the file on the device. target(str): Optional, location to store the file. Uses a temporary file by default. callback(callable): See the documentation for ``a
(path, target=None, callback=None)
| 608 | @context.quietfunc |
| 609 | @with_device |
| 610 | def read(path, target=None, callback=None): |
| 611 | """Download a file from the device, and extract its contents. |
| 612 | |
| 613 | Arguments: |
| 614 | path(str): Path to the file on the device. |
| 615 | target(str): Optional, location to store the file. |
| 616 | Uses a temporary file by default. |
| 617 | callback(callable): See the documentation for |
| 618 | ``adb.protocol.AdbClient.read``. |
| 619 | |
| 620 | Examples: |
| 621 | |
| 622 | .. doctest:: |
| 623 | :skipif: skip_android |
| 624 | |
| 625 | >>> print(adb.read('/proc/version').decode('utf-8')) # doctest: +ELLIPSIS |
| 626 | Linux version ... |
| 627 | >>> adb.read('/does/not/exist') |
| 628 | Traceback (most recent call last): |
| 629 | ... |
| 630 | PwnlibException: Could not stat '/does/not/exist' |
| 631 | """ |
| 632 | with AdbClient() as c: |
| 633 | stat = c.stat(path) |
| 634 | if not stat: |
| 635 | log.error('Could not stat %r' % path) |
| 636 | data = c.read(path, stat['size'], callback=callback) |
| 637 | |
| 638 | if target: |
| 639 | misc.write(target, data) |
| 640 | |
| 641 | return data |
| 642 | |
| 643 | @context.quietfunc |
| 644 | @with_device |