How to use @cumulus/checksum - 10 common examples

To help you get started, we’ve selected a few @cumulus/checksum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa / cumulus / example / spec / parallel / ingestGranule / IngestGranuleSuccessSpec.js View on Github external
.map(async (url) => {
            const extension = path.extname(new URL(url).pathname);
            const sourceFile = s3data.find((d) => d.endsWith(extension));
            const sourceChecksum = await generateChecksumFromStream(
              'cksum',
              fs.createReadStream(require.resolve(sourceFile))
            );
            const file = files.find((f) => f.name.endsWith(extension));

            const filepath = `/${file.bucket}/${file.filepath}`;
            const fileStream = await getDistributionApiFileStream(filepath, accessToken);
            // Compare checksum of downloaded file with expected checksum.
            const downloadChecksum = await generateChecksumFromStream('cksum', fileStream);
            return downloadChecksum === sourceChecksum;
          })
      );
github nasa / cumulus / example / spec / parallel / ingestGranule / IngestGranuleSuccessSpec.js View on Github external
.map(async (url) => {
            const extension = path.extname(new URL(url).pathname);
            const sourceFile = s3data.find((d) => d.endsWith(extension));
            const sourceChecksum = await generateChecksumFromStream(
              'cksum',
              fs.createReadStream(require.resolve(sourceFile))
            );
            const file = files.find((f) => f.name.endsWith(extension));

            const filepath = `/${file.bucket}/${file.filepath}`;
            const fileStream = await getDistributionApiFileStream(filepath, accessToken);
            // Compare checksum of downloaded file with expected checksum.
            const downloadChecksum = await generateChecksumFromStream('cksum', fileStream);
            return downloadChecksum === sourceChecksum;
          })
      );
github nasa / cumulus / example / spec / ingestGranule / IngestUMMGSuccessSpec.js View on Github external
let fileStream;

            if (bucketsConfig.type(file.bucket) === 'protected') {
              const fileUrl = getDistributionFileUrl({
                bucket: file.bucket,
                key: file.filepath
              });
              fileStream = await getDistributionApiFileStream(fileUrl, accessToken);
            }
            else if (bucketsConfig.type(file.bucket) === 'public') {
              fileStream = got.stream(url);
            }

            // Compare checksum of downloaded file with expected checksum.
            const downloadChecksum = await generateChecksumFromStream('cksum', fileStream);
            return downloadChecksum === sourceChecksum;
          })
      );
github nasa / cumulus / example / spec / parallel / distributionAPI / distributionSpec.js View on Github external
it('downloads a public science file', async () => {
        const s3SignedUrl = await getDistributionApiRedirect(publicFilePath);
        const parts = new URL(s3SignedUrl);
        const userName = parts.searchParams.get('x-EarthdataLoginUsername');

        const fileStream = got.stream(s3SignedUrl);
        const downloadChecksum = await generateChecksumFromStream('cksum', fileStream);
        expect(userName).toEqual('unauthenticated user');
        expect(downloadChecksum).toEqual(fileChecksum);
      });
    });
github nasa / cumulus / example / spec / parallel / distributionAPI / distributionSpec.js View on Github external
beforeAll(async () => {
      accessToken = await getTestAccessToken();
      fileChecksum = await generateChecksumFromStream(
        'cksum',
        fs.createReadStream(require.resolve(s3Data[0]))
      );
      publicFilePath = `/${publicBucketName}/${fileKey}`;
      protectedFilePath = `/${protectedBucketName}/${fileKey}`;
      privateFilePath = `/${privateBucketName}/${fileKey}`;
    });
github nasa / cumulus / packages / common / aws.js View on Github external
exports.calculateS3ObjectChecksum = async ({
  algorithm,
  bucket,
  key,
  options
}) => {
  const fileStream = exports.getS3ObjectReadStream(bucket, key);
  return generateChecksumFromStream(algorithm, fileStream, options);
};
github nasa / cumulus / example / spec / ingestGranule / IngestUMMGSuccessSpec.js View on Github external
.map(async (url) => {
            const extension = path.extname(new URL(url).pathname);
            const sourceFile = s3data.find((d) => d.endsWith(extension));
            const sourceChecksum = await generateChecksumFromStream(
              'cksum',
              fs.createReadStream(require.resolve(sourceFile))
            );
            const file = files.find((f) => f.name.endsWith(extension));

            let fileStream;

            if (bucketsConfig.type(file.bucket) === 'protected') {
              const fileUrl = getDistributionFileUrl({
                bucket: file.bucket,
                key: file.filepath
              });
              fileStream = await getDistributionApiFileStream(fileUrl, accessToken);
            }
            else if (bucketsConfig.type(file.bucket) === 'public') {
              fileStream = got.stream(url);
github nasa / cumulus / packages / aws-client / s3.js View on Github external
exports.calculateS3ObjectChecksum = async ({
  algorithm,
  bucket,
  key,
  options
}) => {
  const fileStream = exports.getS3ObjectReadStream(bucket, key);
  return generateChecksumFromStream(algorithm, fileStream, options);
};
github nasa / cumulus / packages / common / aws.js View on Github external
exports.validateS3ObjectChecksum = async ({
  algorithm,
  bucket,
  key,
  expectedSum,
  options
}) => {
  const fileStream = exports.getS3ObjectReadStream(bucket, key);
  if (await validateChecksumFromStream(algorithm, fileStream, expectedSum, options)) {
    return true;
  }
  const msg = `Invalid checksum for S3 object s3://${bucket}/${key} with type ${algorithm} and expected sum ${expectedSum}`;
  throw new errors.InvalidChecksum(msg);
};
github nasa / cumulus / packages / aws-client / s3.js View on Github external
exports.validateS3ObjectChecksum = async ({
  algorithm,
  bucket,
  key,
  expectedSum,
  options
}) => {
  const fileStream = exports.getS3ObjectReadStream(bucket, key);
  if (await validateChecksumFromStream(algorithm, fileStream, expectedSum, options)) {
    return true;
  }
  const msg = `Invalid checksum for S3 object s3://${bucket}/${key} with type ${algorithm} and expected sum ${expectedSum}`;
  throw new InvalidChecksum(msg);
};

@cumulus/checksum

Cumulus checksum utilities

Apache-2.0
Latest version published 15 days ago

Package Health Score

82 / 100
Full package analysis