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

Support reading from gzipped files #17

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

Conversation

Myles1
Copy link

@Myles1 Myles1 commented Aug 10, 2024

Thanks for publishing and maintaining this project. Super helpful stuff!
Feel free to just close this PR if you don't want it. No biggie either way :)

One line description of your change (less than 72 characters)

Support reading from .csv.gz and .json.gz files.

Problem

Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of being the motivation for your change.

I'm compressing the data files locally and need to unzip them before I can run the hpt-validator-cli. This just lets us read gzipped files directly.

Solution

Describe the modifications you've done.

Allow reading directly from gzipped data files.

Test Plan

(Write your test plan here. If you changed any code, please provide us with
clear instructions on how you verified your changes work.)

Create a gzipped data file
$gzip my_file.json
You should now have a file named my_file.json.gz
Run hpt-validator-cli on that new file.
Ensure the results are the same as they were on the unzipped file.

@shaselton-usds
Copy link
Collaborator

@Myles1 Thank you so much for your pull request and your patience.

I think this definitely makes sense and is a value-add.

The one thing that I would request to be changed is to avoid adding the .gz as an additional format to be passed into the CLI. It really isn't a different format as it is a compression of the acceptable formats. Would it be possible to update the PR to auto detect whether the acceptable formats are compressed via .gz and then run through the expected business logic to validate the file appropriately?

Once updated we'll gladly accept this PR with much thanks!

@@ -10,7 +11,7 @@ import {
import { ValidationResult } from "hpt-validator/src/types"
import { InvalidArgumentError } from "commander"

type FileFormat = "csv" | "json"
type FileFormat = "csv" | "json" | "json.gz" | "csv.gz"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove .gz extensions as acceptable format types.

const fileExt = path.extname(filepath).toLowerCase().replace(".", "")
if (["csv", "json"].includes(fileExt)) {
return fileExt as FileFormat
const isGzipped = path.extname(filepath).toLowerCase() === ".gz"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Potentially hoist this check up to determine if one of the acceptable formats is gzipped.

@@ -14,7 +14,9 @@ async function main() {
.addOption(
new Option("-f, --format <string>", "file format of file").choices([
"csv",
"csv.gz",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove these new options as acceptable formats as the main branch of logic would handle this internally.

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

Successfully merging this pull request may close these issues.

2 participants