<commit_before>define(['mac/hfs/BTreeNodeView'], function(BTreeNodeView) {

  'use strict';
  
  var BLOCK_BYTES = 512;
  
  function BTreeByteSink(byteSource) {
    this.byteSource = byteSource;
  }
  BTreeByteSink.prototype = {
    getRawNode: function(number) {
      var offset = number * BLOCK_BYTES;
      var length = BLOCK_BYTES;
      return this.byteSource.slice(offset, offset+length).getBytes();
    },
    getRootNode: function() {
      return this.getRawNode()
        .then(function(rootBytes) {
          return new BTreeNodeView(rootBytes.buffer, rootBytes.byteOffset);
        });
    },
  };
  
  return BTreeByteSink;

});<commit_msg>Flesh out methods<commit_after>define(['mac/hfs/BTreeNodeView'], function(BTreeNodeView) {

  'use strict';
  
  var BLOCK_BYTES = 512;
  
  function BTreeByteSink(byteSource) {
    this.byteSource = byteSource;
  }
  BTreeByteSink.prototype = {
    getRawNode: function(number) {
      return this.byteSource.slice(
        number * BLOCK_BYTES,
        (number + 1) * BLOCK_BYTES).getBytes();
    },
    getNode: function(number) {
      return this.getRawNode()
      .then(function(rawNode) {
        return new BTreeNodeView(rawNode.buffer, rawNode.byteOffset, rawNode.byteLength);
      });
    },
    getHeaderNode: function() {
      var promise = this.getNode(0)
      .then(function(node) {
        if (node.nodeType !== 'header') return Promise.reject('node zero is not a header node');
        return node;
      });
      this.getHeaderNode = function(){ return promise; };
      return promise;
    },
    getFirstLeafNode: function() {
      var self = this;
      var promise = this.getHeaderNode()
      .then(function(node) {
        return self.getNode(node.records[0].firstLeaf);
      });
      this.getFirstLeafNode = function(){ return promise; };
      return promise;
    },
    getRootNode: function() {
      var self = this;
      var promise = this.getHeaderNode()
      .then(function(node) {
        return self.getNode(node.records[0].rootNodeNumber);
      });
      this.getRootNode = function(){ return promise; };
      return promise;
    },
    findLeafForParentDirectoryID: function(parentDirectoryID) {
      var self = this;
      function onNode(node) {
        if (node.nodeType === 'leaf') return node;
        if (node.nodeType !== 'index') return Promise.reject('node is not a leaf or index');
        for (var i = node.records.length - 1; i >= 0; i--) {
          if (parentDirectoryID >= node.records[i].parentDirectoryID) {
            return self.getNode(records[i].nodeNumber).then(onNode);
          }
        }
        return Promise.reject('parent directory ID not found: ' + parentDirectoryID);
      }
      return this.getRootNode().then(onNode);
    },
  };
  
  return BTreeByteSink;

});
{'fraction_non_alphanumeric': 0.12812276945039258, 'fraction_numerical': 0.004282655246252677, 'mean_word_length': 2.7076719576719577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3794417', 'n_tokens_mistral': 865, 'n_tokens_neox': 858, 'n_words': 174}