Append ESPLoader checksum to the just-written image
321888
def append_checksum(self, f, checksum):
        
        align_file_position(f, 16)
        f.write(struct.pack(b'B', checksum))
755037
function verifyChecksum(fileName, checksum) {
  return kew.resolve(hasha.fromFile(fileName, {algorithm: 'sha256'})).then(function (hash) {
    var result = checksum == hash
    if (result) {
      console.log('Verified checksum of previously downloaded file')
    } else {
      console.log('Checksum did not match')
    }
    return result
  }).fail(function (err) {
    console.error('Failed to verify checksum: ', err)
    return false
  })
}
510486
public void registerNewChecksums(File featureDir, String fileName, String checksum) {
        ChecksumData checksums = checksumsMap.get(featureDir);
        if (checksums == null) {
            checksums = new ChecksumData();
            checksumsMap.put(featureDir, checksums);
        }
        checksums.registerNewChecksums(fileName, checksum);
    }
1149888
public static void saveChecksumFile(File csFile, Properties csprops, String reason) {
        FileOutputStream fOut = null;
        try {
            fOut = new FileOutputStream(csFile);
            csprops.store(fOut, null);
            logger.log(Level.FINEST, "Successfully updated the checksum file " + csFile.getAbsolutePath() + reason);
        } catch (Exception e) {
            logger.log(Level.FINEST, "Failed to save checksum file " + csFile.getAbsolutePath() + reason, e);
        } finally {
            InstallUtils.close(fOut);
        }
    }
1221904
function computeChecksums(out, filenames) {
	var result = {};
	filenames.forEach(function (filename) {
		var fullPath = path.join(process.cwd(), out, filename);
		result[filename] = computeChecksum(fullPath);
	});
	return result;
}
801114
public void updateChecksums(File featureDir, ChecksumData checksumData) {

        Collection<File> csFiles = new ArrayList<File>();
        File featureChecksumsDir = new File(featureDir, "checksums");
        getCheckSumFiles(featureChecksumsDir, csFiles);
        File libFeaturesChecksumsDir = new File(Utils.getInstallDir(), "lib/features/checksums");
        if (libFeaturesChecksumsDir.getAbsoluteFile().equals(featureChecksumsDir.getAbsoluteFile())) {
            File libPlatformChecksumsDir = new File(Utils.getInstallDir(), "lib/platform/checksums");
            getCheckSumFiles(libPlatformChecksumsDir, csFiles);
        }

        Properties existingChecksums = initChecksumProps(checksumData.existingChecksums);

        // Update existing cs files to new checksum
        for (File csFile : csFiles) {
            Properties csprops = loadChecksumFile(csFile);
            boolean modified = false;
            for (Entry<Object, Object> csEntry : csprops.entrySet()) {
                Object k = csEntry.getKey();
                if (checksumData.newChecksums.containsKey(k)) {
                    Object newChecksum = checksumData.newChecksums.get(k);
                    if (!csEntry.getValue().equals(newChecksum)) {
                        csprops.put(k, newChecksum);
                        modified = true;
                    }
                }
                if (!checksumData.isIgnoredCSFile(csFile) && existingChecksums.containsKey(k)) {
                    existingChecksums.put(k, csEntry.getValue());
                }
            }
            if (modified) {
                saveChecksumFile(csFile, csprops, " for new checksum.");
            }
        }

        // Update the new cs files to existing checksum
        for (Entry<String, Set<String>> entry : checksumData.existingChecksums.entrySet()) {
            String f = entry.getKey();
            File csFile = new File(featureChecksumsDir, f + ".cs");
            if (csFile.exists()) {
                Properties csprops = loadChecksumFile(csFile);
                boolean modified = false;
                for (String s : entry.getValue()) {
                    if (csprops.containsKey(s) && existingChecksums.containsKey(s)) {
                        String cs = (String) existingChecksums.get(s);
                        if (cs != null && !cs.isEmpty()) {
                            csprops.put(s, cs);
                            modified = true;
                        }
                    }
                }
                if (modified) {
                    saveChecksumFile(csFile, csprops, " for exising checksum.");
                }
            }
        }
    }
716614
def write_chunk(outfile, tag, data=b''):
    

    data = bytes(data)
    # http://www.w3.org/TR/PNG/#5Chunk-layout
    outfile.write(struct.pack("!I", len(data)))
    outfile.write(tag)
    outfile.write(data)
    checksum = zlib.crc32(tag)
    checksum = zlib.crc32(data, checksum)
    checksum &= 2 ** 32 - 1
    outfile.write(struct.pack("!I", checksum))
502631
def format_checksum(checksum_pyxb):
    
    return '{}/{}'.format(
        checksum_pyxb.algorithm.upper().replace('-', ''), checksum_pyxb.value().lower()
    )
1195149
function getChecksum(fs, path, callback) {
  getAttr(fs, path, constants.attributes.checksum, callback);
}
325332
def update_checksum(self, progress_callback=None, chunk_size=None,
                        checksum_kwargs=None, **kwargs):
        """"""
        self.checksum = self.storage(**kwargs).checksum(
            progress_callback=progress_callback, chunk_size=chunk_size,
            **(checksum_kwargs or {}))
579822
function blockChecksums(fs, path, size, callback) {
  var cache = {};

  fs.readFile(path, function (err, data) {
    if (!err) {
      // cache file
      cache[path] = data;
    } else if (err && err.code === 'ENOENT') {
      cache[path] = [];
    } else {
      return callback(err);
    }

    var length = cache[path].length;
    var incr = size;
    var start = 0;
    var end = incr > length ? length : incr;
    var blockIndex = 0;
    var result = [];
    var chunk;
    var weak;
    var strong;

    while (start < length) {
      chunk  = cache[path].slice(start, end);
      weak   = calcWeak32(chunk).sum;
      strong = md5sum(chunk);

      result.push({
        index: blockIndex,
        weak: weak,
        strong: strong
      });
      // update slice indices
      start += incr;
      end = (end + incr) > length ? length : end + incr;
      // update block index
      blockIndex++;
    }

    callback(null, result);
  });
}
897037
def _add_to_checksum(self, checksum, value):
        """"""
        checksum = self._byte_rot_left(checksum, 1)
        checksum = checksum + value
        if (checksum > 255):
            checksum = checksum - 255
        self._debug(PROP_LOGLEVEL_TRACE, "C: " + str(checksum) + " V: " + str(value))
        return checksum
52637
def checksum(path, hashfunc='md5'):
    
    import checksumdir
    hash_func = checksumdir.HASH_FUNCS.get(hashfunc)
    if not hash_func:
        raise NotImplementedError('{} not implemented.'.format(hashfunc))

    if os.path.isdir(path):
        return checksumdir.dirhash(path, hashfunc=hashfunc)

    hashvalues = []
    path_list = glob.glob(path)
    logger.debug("path_list " + str(path_list))
    for path in path_list:
        if os.path.isfile(path):
            hashvalues.append(checksumdir._filehash(path, hashfunc=hash_func))
    logger.debug(str(hashvalues))
    hash = checksumdir._reduce_hash(hashvalues, hashfunc=hash_func)
    return hash
505934
def fix_checksums(self, buff):
        
        import zlib
        import hashlib

        signature = hashlib.sha1(buff[32:]).digest()

        buff = buff[:12] + signature + buff[32:]
        checksum = zlib.adler32(buff[12:])
        buff = buff[:8] + pack("=i", checksum) + buff[12:]

        debug("NEW SIGNATURE %s" % repr(signature))
        debug("NEW CHECKSUM %x" % checksum)

        return buff
822166
def _xfsdump_output(data):
    '''
    
    '''
    out = {}
    summary = []
    summary_block = False

    for line in [l.strip() for l in data.split("\n") if l.strip()]:
        line = re.sub("^xfsdump: ", "", line)
        if line.startswith("session id:"):
            out['Session ID'] = line.split(" ")[-1]
        elif line.startswith("session label:"):
            out['Session label'] = re.sub("^session label: ", "", line)
        elif line.startswith("media file size"):
            out['Media size'] = re.sub(r"^media file size\s+", "", line)
        elif line.startswith("dump complete:"):
            out['Dump complete'] = re.sub(r"^dump complete:\s+", "", line)
        elif line.startswith("Dump Status:"):
            out['Status'] = re.sub(r"^Dump Status:\s+", "", line)
        elif line.startswith("Dump Summary:"):
            summary_block = True
            continue

        if line.startswith(" ") and summary_block:
            summary.append(line.strip())
        elif not line.startswith(" ") and summary_block:
            summary_block = False

    if summary:
        out['Summary'] = ' '.join(summary)

    return out
1072107
function addJpegFromFile( $img, $x, $y, $w = 0, $h = 0 )
    {
        // attempt to add a jpeg image straight from a file, using no GD commands
        // note that this function is unable to operate on a remote file.

        if ( !file_exists( $img ) )
        {
            //echo "FILE NOT EXISTS: $img";
            return;
        }

        $tmp = getimagesize( $img );
        $imageWidth = $tmp[0];
        $imageHeight = $tmp[1];

        if ( isset( $tmp['channels'] ) )
        {
            $channels = $tmp['channels'];
        }
        else
        {
            $channels = 3;
        }

        if ( $w <= 0 && $h <= 0 )
        {
            $w = $imageWidth;
        }
        if ( $w == 0 )
        {
            $w = $h / $imageHeight * $imageWidth;
        }
        if ( $h == 0 )
        {
            $h = $w * $imageHeight / $imageWidth;
        }

        $fp = fopen( $img, 'rb' );

        $data = fread( $fp, filesize( $img ) );

        fclose( $fp );

        $this->addJpegImage_common( $data, $x, $y, $w, $h, $imageWidth, $imageHeight, $channels );
    }
1327491
function c32checksum(dataHex: string) : string {
  const tmpHash = crypto.createHash('sha256').update(Buffer.from(dataHex, 'hex')).digest()
  const dataHash = crypto.createHash('sha256').update(tmpHash).digest()
  const checksum = dataHash.slice(0, 4).toString('hex')
  return checksum
}