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

Handle compressed s3 files with a fragment #1175

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private static ucar.unidata.io.RandomAccessFile downloadAndDecompress(ucar.unida
* @return RandomAccessFile for the object at location
*/
public static ucar.unidata.io.RandomAccessFile getRaf(String location, int buffer_size) throws IOException {
String uriString = location.trim();
String uriString = removeFragment(location.trim());
if (buffer_size <= 0)
buffer_size = default_buffersize;

Expand Down Expand Up @@ -473,6 +473,10 @@ public static ucar.unidata.io.RandomAccessFile getRaf(String location, int buffe
return raf;
}

private static String removeFragment(String uriString) {
return uriString.split("#")[0];
}

private static boolean looksCompressed(String filename) {
// return true if filename ends with a compressed suffix or contains a compressed suffix followed by a delimiter
// (i.e. path to a compressed entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@

@Category(NeedsExternalResource.class)
public class TestS3ExternalCompressionRead {
private static final String compressedObject = "cdms3:noaa-nexrad-level2?1991/07/20/KTLX/KTLX19910720_160529.gz";
private static final String fragment = "#delimiter=/";

@Test
public void testCompressedObjectRead() throws IOException {
String bucket = "noaa-nexrad-level2";
String key = "1991/07/20/KTLX/KTLX19910720_160529.gz";
String s3uri = "cdms3:" + bucket + "?" + key;
testCompressedObjectRead(compressedObject);
}

@Test
public void testCompressedObjectReadWithDelimiterFragment() throws IOException {
testCompressedObjectRead(compressedObject + fragment);
}

private static void testCompressedObjectRead(String s3uri) throws IOException {
System.setProperty(S3TestsCommon.AWS_REGION_PROP_NAME, S3TestsCommon.AWS_G16_REGION);
try (NetcdfFile ncfile = NetcdfFiles.open(s3uri)) {

Expand Down