Skip to content

Commit

Permalink
re commit mp3 fix; remove test code
Browse files Browse the repository at this point in the history
  • Loading branch information
nkan-aot2 authored Jan 29, 2025
1 parent 4f29dc2 commit 37c4b47
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions computingservices/ZippingServices/services/zipperservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,17 @@ def __zipfilesandupload(_message, s3credentials):
_docbytes = __getdocumentbytearray(fileobj, s3credentials)
_formattedbytes = None
_filename, extension = path.splitext(fileobj["s3uripath"])

try:
_formattedbytes = __removesensitivecontent(_docbytes)
if _formattedbytes is not None:
print("_formattedbytes length is {0}".format(len(_formattedbytes)))
else:
print("_formattedbytes is none")
except Exception:
print("error happened while removing sensitive content of {0} ".format(filename))
print(traceback.format_exc())

if extension.lower() == '.pdf':
try:
_formattedbytes = __removesensitivecontent(_docbytes)
if _formattedbytes is not None:
print("_formattedbytes length is {0}".format(len(_formattedbytes)))
else:
print("_formattedbytes is none")
except Exception:
print("error happened while removing sensitive content of {0} ".format(filename))
print(traceback.format_exc())
#added a space to try out code merge on git. 18-Sept-2024
zip.writestr(
filename, _docbytes if _formattedbytes is None else _formattedbytes
Expand Down Expand Up @@ -176,19 +177,3 @@ def __getzipfilepath(foldername, filename):
else filename + ".zip"
)


def __removesensitivecontent(documentbytes):
# clear metadata
reader2 = PyPDF2.PdfReader(BytesIO(documentbytes))
# Check if metadata exists.
if reader2.metadata is not None:
# Create a new PDF file without metadata.
writer = PyPDF2.PdfWriter()
# Copy pages from the original PDF to the new PDF.
for page_num in range(len(reader2.pages)):
page = reader2.pages[page_num]
writer.add_page(page)
#writer.remove_links() # to remove comments.
buffer = BytesIO()
writer.write(buffer)
return buffer.getvalue()

0 comments on commit 37c4b47

Please sign in to comment.