Skip to content

Commit

Permalink
Adds feature of using sozip
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Dec 13, 2023
1 parent b48c463 commit df58854
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 8 additions & 4 deletions API/api_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import re
import shutil
import time
import zipfile
from datetime import datetime
from datetime import datetime as dt
from datetime import timezone

import requests
import sozipfile.sozipfile as zipfile
from celery import Celery

from src.app import RawData, S3FileTransfer
Expand Down Expand Up @@ -76,15 +75,20 @@ def process_raw_data(self, params):
working_dir, os.pardir, f"{exportname_parts[-1]}.zip"
)

zf = zipfile.ZipFile(upload_file_path, "w", zipfile.ZIP_DEFLATED)
zf = zipfile.ZipFile(
upload_file_path,
"w",
compression=zipfile.ZIP_DEFLATED,
chunk_size=zipfile.SOZIP_DEFAULT_CHUNK_SIZE,
)
for file_path in pathlib.Path(working_dir).iterdir():
zf.write(file_path, arcname=file_path.name)
inside_file_size += os.path.getsize(file_path)

# Compressing geojson file
zf.writestr("clipping_boundary.geojson", geom_dump)

utc_now = datetime.now(timezone.utc)
utc_now = dt.now(timezone.utc)
utc_offset = utc_now.strftime("%z")
# Adding metadata readme.txt
readme_content = f"Exported Timestamp (UTC{utc_offset}): {utc_now.strftime('%Y-%m-%d %H:%M:%S')}\n"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ http://127.0.0.1:5000/
curl -d '{"geometry":{"type":"Polygon","coordinates":[[[83.96919250488281,28.194446860487773],[83.99751663208006,28.194446860487773], [83.99751663208006,28.214869548073377],[83.96919250488281,28.214869548073377],[83.96919250488281,28.194446860487773]]]}}' -H 'Content-Type: application/json' http://127.0.0.1:8000/v2/raw-data/current-snapshot/
```

## Introduction of sozip

We use [sozip](https://github.com/sozip/sozip-spec) optimization while we zip the files , This won't change anything the existing usecase for .zip . Learn more about it in attached link . You can drag and drop zip generated in new version of QGIS without unzipping


## Tests

- Raw Data API uses pytest for tests, navigate to the root directory and install package in editable mode:
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ osm-login-python==0.0.2
mkdocs-material==8.5.11
mkdocs-jupyter==0.22.0
neoteroi-mkdocs==0.1.2
pdocs==1.0.1
pdocs==1.0.1

##sozipfile
sozipfile==0.3.2

0 comments on commit df58854

Please sign in to comment.