<commit_before>/*
 *  FSTransport.js
 *
 *  <NAME>
 *  IOTDB.org
 *  2015-03-07
 *
 *  Copyright [2013-2015] [<NAME>]
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

"use strict";

var iotdb = require('iotdb');
var _ = iotdb._;
var bunyan = iotdb.bunyan;

var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var watch = require('watch');

var util = require('util');
var url = require('url');

var logger = bunyan.createLogger({
    name: 'iotdb-transport-fs',
    module: 'FSTransport',
});

/* --- constructor --- */

/**
 *  File System based Transport
 *  <p>
 *  See {iotdb.transporter.Transport#Transport} for documentation.
 */
var FSTransport = function (initd) {
    var self = this;

    self.initd = _.defaults(
        initd,
        {
            channel: iotdb.transporter.channel,
            unchannel: iotdb.transporter.unchannel,
            encode: _encode,
            decode: _decode,
            pack: _pack,
            unpack: _unpack,
        },
        iotdb.keystore().get("/transports/FSTransport/initd"),
        {
            prefix: path.join(process.cwd(), ".iotdb", "fs"),
            flat_band: null,
        }
    );

    /* for consistency but not used */
    self.native = {};
    
    /* ignore errors - they will occur later anyway */
    mkdirp.sync(self.initd.prefix, function(error) {
    });
};

FSTransport.prototype = new iotdb.transporter.Transport;

/* --- methods --- */

/**
 *  See {iotdb.transporter.Transport#list} for documentation.
 */
FSTransport.prototype.list = function(paramd, callback) {
    var self = this;

    if (arguments.length === 1) {
        paramd = {};
        callback = arguments[0];
    }

    self._validate_list(paramd, callback);

    fs.readdir(self.initd.prefix, function(error, names) {
        if (error) {
            return;
        }

        var _pop = function() {
            if (names.length === 0) {
                return callback({
                    end: true,
                });
            }

            var name = names.pop();
            var folder = path.join(self.initd.prefix, name);

            var result = self.initd.unchannel(self.initd, folder);
            if (result) {
                callback({
                    id: result[0],
                });
                _pop();
            } else {
                /*
                fs.stat(folder, function(error, stbuf) {
                    if (error) {
                    } else if (stbuf.isDirectory()) {
                        callback([ folder ]);
                    } else {
                    }

                    _pop();
                });
                */<commit_msg>list: callback return true stops list<commit_after>/*
 *  FSTransport.js
 *
 *  <NAME>
 *  IOTDB.org
 *  2015-03-07
 *
 *  Copyright [2013-2015] [<NAME>]
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

"use strict";

var iotdb = require('iotdb');
var _ = iotdb._;
var bunyan = iotdb.bunyan;

var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var watch = require('watch');

var util = require('util');
var url = require('url');

var logger = bunyan.createLogger({
    name: 'iotdb-transport-fs',
    module: 'FSTransport',
});

/* --- constructor --- */

/**
 *  File System based Transport
 *  <p>
 *  See {iotdb.transporter.Transport#Transport} for documentation.
 */
var FSTransport = function (initd) {
    var self = this;

    self.initd = _.defaults(
        initd,
        {
            channel: iotdb.transporter.channel,
            unchannel: iotdb.transporter.unchannel,
            encode: _encode,
            decode: _decode,
            pack: _pack,
            unpack: _unpack,
        },
        iotdb.keystore().get("/transports/FSTransport/initd"),
        {
            prefix: path.join(process.cwd(), ".iotdb", "fs"),
            flat_band: null,
        }
    );

    /* for consistency but not used */
    self.native = {};
    
    /* ignore errors - they will occur later anyway */
    mkdirp.sync(self.initd.prefix, function(error) {
    });
};

FSTransport.prototype = new iotdb.transporter.Transport;

/* --- methods --- */

/**
 *  See {iotdb.transporter.Transport#list} for documentation.
 */
FSTransport.prototype.list = function(paramd, callback) {
    var self = this;

    if (arguments.length === 1) {
        paramd = {};
        callback = arguments[0];
    }

    self._validate_list(paramd, callback);

    fs.readdir(self.initd.prefix, function(error, names) {
        if (error) {
            return;
        }

        var _pop = function() {
            if (names.length === 0) {
                callback({
                    end: true,
                });
                return;
            }

            var name = names.pop();
            var folder = path.join(self.initd.prefix, name);

            var result = self.initd.unchannel(self.initd, folder);
            if (result) {
                if (callback({
                    id: result[0],
                })) {
                    names = [];
                };

                _pop();
{'fraction_non_alphanumeric': 0.12885927851803705, 'fraction_numerical': 0.007799805004874878, 'mean_word_length': 1.8574744661095637, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '293671', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1776, 'n_words': 480}