如何通过换行符在Node.js中拆分缓冲区

时间:2019-07-15 18:06:44

标签: node.js binary byte buffer

假设我们有一个缓冲区b:

function get_unpaid_submitted() {        
    global $wpdb;

    $unpaid_submitted = $wpdb->get_col( $wpdb->prepare( "
        SELECT posts.ID
        FROM {$wpdb->posts} AS posts
        WHERE posts.post_status = 'wc-on-hold'
        AND posts.post_date < %s
        ", date( 'Y-m-d H:i:s', strtotime('-72 hours') ) ) );

    return $unpaid_submitted;
}
function wc_cancel_unpaid_submitted() {
    $unpaid_submit = get_unpaid_submitted();
    if ( $unpaid_submit ) {                
        foreach ( $unpaid_submit as $unpaid_order ) {                        
            $order = wc_get_order( $unpaid_order );
            $order -> update_status( 'cancelled', __( 'Orden cancelada por falt de pago.', 'woocommerce') );
        }
    }        
}
add_action('woocommerce_cancel_unpaid_submitted', 'wc_cancel_unpaid_submitted',10);

是否可以通过换行符将缓冲区分为N个缓冲区?不先转换为字符串?因此结果将是这样的:

const b = Buffer.from('foo\nbar\nbaz');

1 个答案:

答案 0 :(得分:1)

您可以使用buf.indexOf在缓冲区中查找换行符,然后根据您的操作,可以使用buf.copy复制到新的Buffer对象中。