Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return archive in zip stream #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

yichen88
Copy link
Contributor

Please check if the PR fulfills these requirements (please use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem ? If so, link to this issue using '#XXX' and skip the rest
#31

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change or deprecate an API? If yes, check the following:

  • The Breaking Change or Deprecated label has been added
  • The migration guide has been updated in the github wiki (What changes might users need to make in their application due to this PR?)

Other information:

(if any of the questions/checkboxes don't apply, please delete them entirely)

@yichen88 yichen88 force-pushed the not_store_zip_locally branch from f598c6a to 7169c9b Compare March 24, 2020 16:03
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 2 Code Smells

76.7% 76.7% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@mathbagu mathbagu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view, you miss something. When I created the issue, I would to create a ZipInputStream to avoid creating a temporary folder on the server side. I don't understand how this PR how solve this issue?

Comment on lines +82 to +90
try {
if (Files.isDirectory(someFileToZip)) {
addDirectory(zos, pathInZip);
} else {
addFile(zos, someFileToZip, pathInZip);
}
} catch (IOException e) {
throw new AfsStorageException(e.getMessage());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this lambda smaller, you should catch exception in addDirectory and addFile

Comment on lines +58 to +75
public static ZipInputStream zip(Path dir, boolean deleteDirectory) throws IOException {
byte[] bytes;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
Stream<Path> walk = Files.walk(dir)) {
zip(walk, dir, zos);
zos.close();
baos.close();
bytes = baos.toByteArray();
} catch (IOException | AfsStorageException e) {
throw new IOException(e);
}

if (deleteDirectory) {
deleteDirectory(dir);
}
return new ZipInputStream(new ByteArrayInputStream(bytes));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you creating a pipe (i.e. creating a zip from a path, and returning a input-stream for this path)?
In that case, could you use PipedInputStream/PipedOutputStream as it's done in NetworkXml.copy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants