fcs
2025-04-10 0163870d662dc5b7d69ceff977490ede594f7d82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
const fs = require('fs');
const util = require('util');
const is = require('@sindresorhus/is');
const isFormData = require('./is-form-data');
 
module.exports = async options => {
    const {body} = options;
 
    if (options.headers['content-length']) {
        return Number(options.headers['content-length']);
    }
 
    if (!body && !options.stream) {
        return 0;
    }
 
    if (is.string(body)) {
        return Buffer.byteLength(body);
    }
 
    if (isFormData(body)) {
        return util.promisify(body.getLength.bind(body))();
    }
 
    if (body instanceof fs.ReadStream) {
        const {size} = await util.promisify(fs.stat)(body.path);
        return size;
    }
 
    return null;
};