Browse Source

Add --size-hint option

master
JustAnotherArchivist 1 month ago
parent
commit
81bba9a631
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      ia-upload-stream

+ 5
- 1
ia-upload-stream View File

@@ -215,7 +215,7 @@ def wait_first(tasks, parts):
logger.info(f'Upload of part {partNumber} OK, ETag: {eTag}')


def upload(item, filename, metadata, *, iaConfigFile = None, partSize = 100*1024*1024, tries = 3, partTimeout = None, concurrency = 1, queueDerive = True, keepOldVersion = True, complete = True, uploadId = None, parts = None, progress = True):
def upload(item, filename, metadata, *, iaConfigFile = None, partSize = 100*1024*1024, tries = 3, partTimeout = None, concurrency = 1, queueDerive = True, keepOldVersion = True, complete = True, uploadId = None, parts = None, progress = True, sizeHint = None):
f = sys.stdin.buffer

# Read `ia` config
@@ -225,6 +225,8 @@ def upload(item, filename, metadata, *, iaConfigFile = None, partSize = 100*1024
headers = {'Authorization': f'LOW {access}:{secret}'}
metadataHeaders = metadata_to_headers(metadata)
initialHeaders = {**headers, 'x-amz-auto-make-bucket': '1', **metadataHeaders}
if sizeHint:
initialHeaders['x-archive-size-hint'] = str(sizeHint)
extraHeaders = {'x-archive-queue-derive': '1' if queueDerive else '0', 'x-archive-keep-old-version': '1' if keepOldVersion else '0'}

# Always read the first part
@@ -406,6 +408,7 @@ def main():
parser.add_argument('--concurrency', '--concurrent', type = int, default = 1, metavar = 'N', help = 'upload N parts in parallel (default: 1)')
parser.add_argument('--no-complete', dest = 'complete', action = 'store_false', help = 'disable completing the upload when stdin is exhausted')
parser.add_argument('--no-progress', dest = 'progress', action = 'store_false', help = 'disable progress bar')
parser.add_argument('--size-hint', dest = 'sizeHint', type = size, help = "size hint for the total item size; only has an effect if the item doesn't exist yet")
parser.add_argument('--upload-id', dest = 'uploadId', help = 'upload ID when resuming or aborting an upload')
parser.add_argument('--parts', type = parts, help = 'previous parts data for resumption; can only be used with --upload-id')
parser.add_argument('--abort', action = 'store_true', help = 'aborts an upload; can only be used with --upload-id; most other options are ignored when this is used')
@@ -441,6 +444,7 @@ def main():
uploadId = args.uploadId,
parts = args.parts,
progress = args.progress,
sizeHint = args.sizeHint,
)
elif args.list:
list_uploads(args.item, tries = args.tries)


Loading…
Cancel
Save